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

AK/URLParser: Add spec comments to parse_opaque_host()

This commit is contained in:
Kemal Zebari 2023-10-04 00:02:06 -07:00 committed by Andrew Kaster
parent 2d27998f28
commit 369f1d72ba

View file

@ -39,8 +39,10 @@ static void report_validation_error(SourceLocation const& location = SourceLocat
dbgln_if(URL_PARSER_DEBUG, "URLParser::basic_parse: Validation error! {}", location); dbgln_if(URL_PARSER_DEBUG, "URLParser::basic_parse: Validation error! {}", location);
} }
// https://url.spec.whatwg.org/#concept-opaque-host-parser
static Optional<URL::Host> parse_opaque_host(StringView input) static Optional<URL::Host> parse_opaque_host(StringView input)
{ {
// 1. If input contains a forbidden host code point, host-invalid-code-point validation error, return failure.
auto forbidden_host_characters_excluding_percent = "\0\t\n\r #/:<>?@[\\]^|"sv; auto forbidden_host_characters_excluding_percent = "\0\t\n\r #/:<>?@[\\]^|"sv;
for (auto character : forbidden_host_characters_excluding_percent) { for (auto character : forbidden_host_characters_excluding_percent) {
if (input.contains(character)) { if (input.contains(character)) {
@ -48,8 +50,13 @@ static Optional<URL::Host> parse_opaque_host(StringView input)
return {}; return {};
} }
} }
// FIXME: If input contains a code point that is not a URL code point and not U+0025 (%), validation error.
// FIXME: If input contains a U+0025 (%) and the two code points following it are not ASCII hex digits, validation error. // 2. If input contains a code point that is not a URL code point and not U+0025 (%), invalid-URL-unit validation error.
// 3. If input contains a U+0025 (%) and the two code points following it are not ASCII hex digits, invalid-URL-unit validation error.
// NOTE: These steps are not implemented because they are not cheap checks and exist just to report validation errors. With how we
// currently report validation errors, they are only useful for debugging efforts in the URL parsing code.
// 4. Return the result of running UTF-8 percent-encode on input using the C0 control percent-encode set.
return String::from_deprecated_string(URL::percent_encode(input, URL::PercentEncodeSet::C0Control)).release_value_but_fixme_should_propagate_errors(); return String::from_deprecated_string(URL::percent_encode(input, URL::PercentEncodeSet::C0Control)).release_value_but_fixme_should_propagate_errors();
} }