From ca1ab54e0c0992757a7860d48c4e72b1b7b3fc16 Mon Sep 17 00:00:00 2001 From: Smaug Date: Wed, 12 Jul 2023 21:16:02 +0200 Subject: [PATCH] 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 --- data-url/src/lib.rs | 1 + data-url/tests/data-urls.json | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/data-url/src/lib.rs b/data-url/src/lib.rs index b81a330c6..d7ceeb111 100644 --- a/data-url/src/lib.rs +++ b/data-url/src/lib.rs @@ -298,6 +298,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 { diff --git a/data-url/tests/data-urls.json b/data-url/tests/data-urls.json index f318d1f3e..549b19a41 100644 --- a/data-url/tests/data-urls.json +++ b/data-url/tests/data-urls.json @@ -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]],