mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
AK: Fix logic error in urldecode() percent-decoding
We also need to append the raw consumed value if *either* of the two characters after the % isn't a hex digit, not only if *both* aren't. Fixes #4257.
This commit is contained in:
parent
4c8c149612
commit
ba020a5907
2 changed files with 15 additions and 1 deletions
|
@ -172,9 +172,22 @@ TEST_CASE(data_url)
|
|||
EXPECT_EQ(url.protocol(), "data");
|
||||
EXPECT_EQ(url.host(), "");
|
||||
EXPECT_EQ(url.data_mime_type(), "text/html");
|
||||
EXPECT_EQ(url.data_payload(), "test");
|
||||
EXPECT_EQ(url.to_string(), "data:text/html,test");
|
||||
}
|
||||
|
||||
TEST_CASE(data_url_encoded)
|
||||
{
|
||||
URL url("data:text/html,Hello%20friends%2C%0X%X0");
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.protocol(), "data");
|
||||
EXPECT_EQ(url.host(), "");
|
||||
EXPECT_EQ(url.data_mime_type(), "text/html");
|
||||
EXPECT_EQ(url.data_payload(), "Hello friends,%0X%X0");
|
||||
// FIXME: Surely this should be URL-encoded again?!
|
||||
EXPECT_EQ(url.to_string(), "data:text/html,Hello friends,%0X%X0");
|
||||
}
|
||||
|
||||
TEST_CASE(data_url_base64_encoded)
|
||||
{
|
||||
URL url("data:text/html;base64,test");
|
||||
|
@ -182,6 +195,7 @@ TEST_CASE(data_url_base64_encoded)
|
|||
EXPECT_EQ(url.protocol(), "data");
|
||||
EXPECT_EQ(url.host(), "");
|
||||
EXPECT_EQ(url.data_mime_type(), "text/html");
|
||||
EXPECT_EQ(url.data_payload(), "test");
|
||||
EXPECT_EQ(url.to_string(), "data:text/html;base64,test");
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ String urldecode(const StringView& input)
|
|||
builder.append(consume());
|
||||
continue;
|
||||
}
|
||||
if (!is_ascii_hex_digit(peek(1)) && !is_ascii_hex_digit(peek(2))) {
|
||||
if (!is_ascii_hex_digit(peek(1)) || !is_ascii_hex_digit(peek(2))) {
|
||||
builder.append(consume());
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue