1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:27:46 +00:00

AK: Clear buffer after leaving CannotBeABaseUrlPath in URLParser

By not clearing the buffer, we were leaking the path part of a URL into
the query for URLs without an authority component (no '//host').

This could be seen most noticeably in mailto: URLs with header fields
set, as the query part of `mailto:user@example.com?subject=test` was
parsed to `user@example.comsubject=test`.

data: URLs didn't have this problem, because we have a special case for
parsing them.
This commit is contained in:
Karol Kosek 2023-07-06 19:13:42 +02:00 committed by Andreas Kling
parent 28fdc7af05
commit 58017a0581
2 changed files with 17 additions and 1 deletions

View file

@ -226,6 +226,20 @@ TEST_CASE(mailto_url)
EXPECT_EQ(url.serialize(), "mailto:mail@example.com");
}
TEST_CASE(mailto_url_with_subject)
{
URL url("mailto:mail@example.com?subject=test"sv);
EXPECT(url.is_valid());
EXPECT_EQ(url.scheme(), "mailto");
EXPECT(url.host().has<Empty>());
EXPECT_EQ(url.port_or_default(), 0);
EXPECT_EQ(url.path_segment_count(), 1u);
EXPECT_EQ(url.path_segment_at_index(0), "mail@example.com");
EXPECT_EQ(url.query(), "subject=test");
EXPECT(url.fragment().is_null());
EXPECT_EQ(url.serialize(), "mailto:mail@example.com?subject=test");
}
TEST_CASE(data_url)
{
URL url("data:text/html,test"sv);