Skip to content

Commit

Permalink
Fix non-base64 data URLs with % character not followed by hex digits
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SmaugPool committed Jul 12, 2023
1 parent a3e07c7 commit 6ad3fc5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions data-url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ where
// before this special byte
if i > slice_start {
write_bytes(&bytes[slice_start..i])?;
slice_start = i;
}
// Then deal with the special byte.
match byte {
Expand Down
18 changes: 18 additions & 0 deletions data-url/tests/data-urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@
["data:text/plain;Charset=UTF-8,%C2%B1",
"text/plain;charset=UTF-8",
[194, 177]],
["data:text/plain,%",
"text/plain",
[37]],
["data:text/plain,X%",
"text/plain",
[88, 37]],
["data:text/plain,X%%",
"text/plain",
[88, 37, 37]],
["data:text/plain;Charset=UTF-8,X%X",
"text/plain;charset=UTF-8",
[88, 37, 88]],
["data:text/plain;Charset=UTF-8,X%0",
"text/plain;charset=UTF-8",
[88, 37, 48]],
["data:text/plain;Charset=UTF-8,X%0X",
"text/plain;charset=UTF-8",
[88, 37, 48, 88]],
["data:text/plain;charset=windows-1252,áñçə💩",
"text/plain;charset=windows-1252",
[195, 161, 195, 177, 195, 167, 201, 153, 240, 159, 146, 169]],
Expand Down

0 comments on commit 6ad3fc5

Please sign in to comment.