diff --git a/Libraries/LibURL/Pattern/Canonicalization.cpp b/Libraries/LibURL/Pattern/Canonicalization.cpp index d79c236b85c..55a19e94771 100644 --- a/Libraries/LibURL/Pattern/Canonicalization.cpp +++ b/Libraries/LibURL/Pattern/Canonicalization.cpp @@ -151,7 +151,7 @@ PatternErrorOr canonicalize_a_port(String const& port_value, Optional canonicalize_a_pathname(String const& value) +String canonicalize_a_pathname(String const& value) { // 1. If value is the empty string, then return value. if (value.is_empty()) @@ -171,22 +171,17 @@ PatternErrorOr canonicalize_a_pathname(String const& value) // 5. Let dummyURL be a new URL record. URL dummy_url; - // 6. Let parseResult be the result of running basic URL parser given modified value with dummyURL - // as url and path start state as state override. - auto parse_result = Parser::basic_parse(modified_value.string_view(), {}, &dummy_url, Parser::State::PathStart); + // 6. Run basic URL parser given modified value with dummyURL as url and path start state as state override. + (void)Parser::basic_parse(modified_value.string_view(), {}, &dummy_url, Parser::State::PathStart); - // 7. If parseResult is failure, then throw a TypeError. - if (!parse_result.has_value()) - return ErrorInfo { "Failed to canonicalize pathname string"_string }; - - // 8. Let result be the result of URL path serializing dummyURL. + // 7. Let result be the result of URL path serializing dummyURL. auto result = dummy_url.serialize_path(); - // 9. If leading slash is false, then set result to the code point substring from 2 to the end of the string within result. + // 8. If leading slash is false, then set result to the code point substring from 2 to the end of the string within result. if (!leading_slash) result = MUST(String::from_utf8(result.code_points().unicode_substring_view(2).as_string())); - // 10. Return result. + // 9. Return result. return result; } @@ -216,7 +211,7 @@ PatternErrorOr canonicalize_an_opaque_pathname(String const& value) } // https://urlpattern.spec.whatwg.org/#canonicalize-a-search -PatternErrorOr canonicalize_a_search(String const& value) +String canonicalize_a_search(String const& value) { // 1. If value is the empty string, return value. if (value.is_empty()) @@ -228,20 +223,16 @@ PatternErrorOr canonicalize_a_search(String const& value) // 3. Set dummyURL’s query to the empty string. dummy_url.set_query(String {}); - // 4. Let parseResult be the result of running basic URL parser given value with dummyURL as url and query state as state override. - auto parse_result = Parser::basic_parse(value, {}, &dummy_url, Parser::State::Query); + // 4. Run basic URL parser given value with dummyURL as url and query state as state override. + (void)Parser::basic_parse(value, {}, &dummy_url, Parser::State::Query); - // 5. If parseResult is failure, then throw a TypeError. - if (!parse_result.has_value()) - return ErrorInfo { "Failed to canonicalize query string"_string }; - - // 6. Return dummyURL’s query. + // 5. Return dummyURL’s query. VERIFY(dummy_url.query().has_value()); return *dummy_url.query(); } // https://urlpattern.spec.whatwg.org/#canonicalize-a-hash -PatternErrorOr canonicalize_a_hash(String const& value) +String canonicalize_a_hash(String const& value) { // 1. If value is the empty string, return value. if (value.is_empty()) @@ -253,14 +244,10 @@ PatternErrorOr canonicalize_a_hash(String const& value) // 3. Set dummyURL’s fragment to the empty string. dummy_url.set_fragment(String {}); - // 4. Let parseResult be the result of running basic URL parser given value with dummyURL as url and fragment state as state override. - auto parse_result = Parser::basic_parse(value, {}, &dummy_url, Parser::State::Fragment); + // 4. Run basic URL parser given value with dummyURL as url and fragment state as state override. + (void)Parser::basic_parse(value, {}, &dummy_url, Parser::State::Fragment); - // 5. If parseResult is failure, then throw a TypeError. - if (!parse_result.has_value()) - return ErrorInfo { "Failed to canonicalize query string"_string }; - - // 6. Return dummyURL’s fragment. + // 5. Return dummyURL’s fragment. VERIFY(dummy_url.fragment().has_value()); return *dummy_url.fragment(); } diff --git a/Libraries/LibURL/Pattern/Canonicalization.h b/Libraries/LibURL/Pattern/Canonicalization.h index f3333ff34ff..ef4b9d93d5a 100644 --- a/Libraries/LibURL/Pattern/Canonicalization.h +++ b/Libraries/LibURL/Pattern/Canonicalization.h @@ -17,9 +17,9 @@ String canonicalize_a_password(String const&); PatternErrorOr canonicalize_a_hostname(String const&); PatternErrorOr canonicalize_an_ipv6_hostname(String const&); PatternErrorOr canonicalize_a_port(String const&, Optional const& protocol_value = {}); -PatternErrorOr canonicalize_a_pathname(String const&); +String canonicalize_a_pathname(String const&); PatternErrorOr canonicalize_an_opaque_pathname(String const&); -PatternErrorOr canonicalize_a_search(String const&); -PatternErrorOr canonicalize_a_hash(String const&); +String canonicalize_a_search(String const&); +String canonicalize_a_hash(String const&); } diff --git a/Libraries/LibURL/Pattern/Init.cpp b/Libraries/LibURL/Pattern/Init.cpp index 5acf0feb22e..eab00e6d5bc 100644 --- a/Libraries/LibURL/Pattern/Init.cpp +++ b/Libraries/LibURL/Pattern/Init.cpp @@ -134,7 +134,7 @@ static PatternErrorOr process_pathname_for_init(String const& pathname_v } // https://urlpattern.spec.whatwg.org/#process-search-for-init -static PatternErrorOr process_search_for_init(String const& value, PatternProcessType type) +static String process_search_for_init(String const& value, PatternProcessType type) { // 1. Let strippedValue be the given value with a single leading U+003F (?) removed, if any. auto stripped_value = value; @@ -150,7 +150,7 @@ static PatternErrorOr process_search_for_init(String const& value, Patte } // https://urlpattern.spec.whatwg.org/#process-hash-for-init -static PatternErrorOr process_hash_for_init(String const& value, PatternProcessType type) +static String process_hash_for_init(String const& value, PatternProcessType type) { // 1. Let strippedValue be the given value with a single leading U+0023 (#) removed, if any. auto stripped_value = value; @@ -346,11 +346,11 @@ PatternErrorOr process_a_url_pattern_init(Init const& init, PatternProcess // 18. If init["search"] exists then set result["search"] to the result of process search for init given init["search"] and type. if (init.search.has_value()) - result.search = TRY(process_search_for_init(init.search.value(), type)); + result.search = process_search_for_init(init.search.value(), type); // 19. If init["hash"] exists then set result["hash"] to the result of process hash for init given init["hash"] and type. if (init.hash.has_value()) - result.hash = TRY(process_hash_for_init(init.hash.value(), type)); + result.hash = process_hash_for_init(init.hash.value(), type); // 20. Return result. return result;