Skip to content

Commit e654efb

Browse files
authored
Fix non-base64 data URLs with % character not followed by hex digits (#797)
When writing accumulated "non-special" characters, `slice_start` must be updated as some later conditionals/pattern matches don't update it like the case when `%` is not followed by 2 hex digits. This fixes #795
1 parent 8a1e3e2 commit e654efb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

data-url/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ where
298298
// before this special byte
299299
if i > slice_start {
300300
write_bytes(&bytes[slice_start..i])?;
301+
slice_start = i;
301302
}
302303
// Then deal with the special byte.
303304
match byte {

data-url/tests/data-urls.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@
5252
["data:text/plain;Charset=UTF-8,%C2%B1",
5353
"text/plain;charset=UTF-8",
5454
[194, 177]],
55+
["data:text/plain,%",
56+
"text/plain",
57+
[37]],
58+
["data:text/plain,X%",
59+
"text/plain",
60+
[88, 37]],
61+
["data:text/plain,X%%",
62+
"text/plain",
63+
[88, 37, 37]],
64+
["data:text/plain;Charset=UTF-8,X%X",
65+
"text/plain;charset=UTF-8",
66+
[88, 37, 88]],
67+
["data:text/plain;Charset=UTF-8,X%0",
68+
"text/plain;charset=UTF-8",
69+
[88, 37, 48]],
70+
["data:text/plain;Charset=UTF-8,X%0X",
71+
"text/plain;charset=UTF-8",
72+
[88, 37, 48, 88]],
5573
["data:text/plain;charset=windows-1252,áñçə💩",
5674
"text/plain;charset=windows-1252",
5775
[195, 161, 195, 177, 195, 167, 201, 153, 240, 159, 146, 169]],

0 commit comments

Comments
 (0)