Skip to content

Commit 6ad3fc5

Browse files
committed
Fix non-base64 data URLs with % character not followed by hex digits
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 a3e07c7 commit 6ad3fc5

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
@@ -282,6 +282,7 @@ where
282282
// before this special byte
283283
if i > slice_start {
284284
write_bytes(&bytes[slice_start..i])?;
285+
slice_start = i;
285286
}
286287
// Then deal with the special byte.
287288
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)