AK: Percent encode URL fragments when parsed

This fixes URL fragments containing characters in the fragment encoding
set that were not being correctly percent encoded.
This commit is contained in:
Shannon Booth 2023-08-14 16:25:21 +12:00 committed by Andrew Kaster
parent 4eab37f391
commit cb4c279e90
3 changed files with 14 additions and 2 deletions

View file

@ -1635,10 +1635,11 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
if (code_point == '%' && !remaining_starts_with_two_ascii_hex_digits())
report_validation_error();
// FIXME: 3. UTF-8 percent-encode c using the fragment percent-encode set and append the result to urls fragment.
// 3. UTF-8 percent-encode c using the fragment percent-encode set and append the result to urls fragment.
// NOTE: The percent-encode is done on EOF on the entire buffer.
buffer.append_code_point(code_point);
} else {
url->m_fragment = buffer.to_string().release_value_but_fixme_should_propagate_errors();
url->m_fragment = String::from_deprecated_string(percent_encode_after_encoding(buffer.string_view(), URL::PercentEncodeSet::Fragment)).release_value_but_fixme_should_propagate_errors();
buffer.clear();
}
break;

View file

@ -48,3 +48,13 @@ port => '0'
pathname => ''
search => ''
hash => ''
http://serenityos.org/cat?dog#meow"woof
protocol => 'http:'
username => ''
password => ''
host => 'serenityos.org'
hostname => 'serenityos.org'
port => ''
pathname => '/cat'
search => '?dog'
hash => '#meow%22woof'

View file

@ -21,6 +21,7 @@
'http://[1:0:1:0:1:0:1:0]',
'http://[1:1:0:0:1:0:0:0]/',
'unknown://serenityos.org:0',
'http://serenityos.org/cat?dog#meow"woof',
]) {
printURL(url);
}