From 4bb211ba888b8fed9fd3da3163dc6e823d7e3c8a Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 11 Aug 2024 00:05:22 +1200 Subject: [PATCH] LibURL: Make percent_encode_after_encoding infallible --- Userland/Libraries/LibURL/Parser.cpp | 10 +++++----- Userland/Libraries/LibURL/Parser.h | 2 +- Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibURL/Parser.cpp b/Userland/Libraries/LibURL/Parser.cpp index 97824ad2f78..3c2f3c4a3eb 100644 --- a/Userland/Libraries/LibURL/Parser.cpp +++ b/Userland/Libraries/LibURL/Parser.cpp @@ -770,13 +770,13 @@ void Parser::shorten_urls_path(URL& url) } // https://url.spec.whatwg.org/#string-percent-encode-after-encoding -ErrorOr Parser::percent_encode_after_encoding(TextCodec::Encoder& encoder, StringView input, PercentEncodeSet percent_encode_set, bool space_as_plus) +String Parser::percent_encode_after_encoding(TextCodec::Encoder& encoder, StringView input, PercentEncodeSet percent_encode_set, bool space_as_plus) { // 1. Let encodeOutput be an empty I/O queue. StringBuilder output; // 2. Set potentialError to the result of running encode or fail with inputQueue, encoder, and encodeOutput. - TRY(encoder.process( + MUST(encoder.process( Utf8View(input), // 3. For each byte of encodeOutput converted to a byte sequence: @@ -813,7 +813,7 @@ ErrorOr Parser::percent_encode_after_encoding(TextCodec::Encoder& encode })); // 6. Return output. - return output.to_string(); + return MUST(output.to_string()); } // https://url.spec.whatwg.org/#concept-basic-url-parser @@ -1703,7 +1703,7 @@ URL Parser::basic_parse(StringView raw_input, Optional const& base_url, Opt auto query_percent_encode_set = url->is_special() ? PercentEncodeSet::SpecialQuery : PercentEncodeSet::Query; // 2. Percent-encode after encoding, with encoding, buffer, and queryPercentEncodeSet, and append the result to url’s query. - url->m_data->query = percent_encode_after_encoding(*encoder, buffer.string_view(), query_percent_encode_set).release_value_but_fixme_should_propagate_errors(); + url->m_data->query = percent_encode_after_encoding(*encoder, buffer.string_view(), query_percent_encode_set); // 3. Set buffer to the empty string. buffer.clear(); @@ -1745,7 +1745,7 @@ URL Parser::basic_parse(StringView raw_input, Optional const& base_url, Opt // NOTE: The percent-encode is done on EOF on the entire buffer. buffer.append_code_point(code_point); } else { - url->m_data->fragment = percent_encode_after_encoding(*encoder, buffer.string_view(), PercentEncodeSet::Fragment).release_value_but_fixme_should_propagate_errors(); + url->m_data->fragment = percent_encode_after_encoding(*encoder, buffer.string_view(), PercentEncodeSet::Fragment); buffer.clear(); } break; diff --git a/Userland/Libraries/LibURL/Parser.h b/Userland/Libraries/LibURL/Parser.h index 0cfdd07ceed..c52f9e6d84a 100644 --- a/Userland/Libraries/LibURL/Parser.h +++ b/Userland/Libraries/LibURL/Parser.h @@ -61,7 +61,7 @@ public: static URL basic_parse(StringView input, Optional const& base_url = {}, Optional url = {}, Optional state_override = {}, Optional encoding = {}); // https://url.spec.whatwg.org/#string-percent-encode-after-encoding - static ErrorOr percent_encode_after_encoding(TextCodec::Encoder&, StringView input, PercentEncodeSet percent_encode_set, bool space_as_plus = false); + static String percent_encode_after_encoding(TextCodec::Encoder&, StringView input, PercentEncodeSet percent_encode_set, bool space_as_plus = false); // https://url.spec.whatwg.org/#concept-host-serializer static ErrorOr serialize_host(Host const&); diff --git a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp index 138952ffa99..395f152556c 100644 --- a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp +++ b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp @@ -62,10 +62,10 @@ ErrorOr url_encode(Vector const& tuples, StringView encoding // 1. Assert: tuple’s name and tuple’s value are scalar value strings. // 2. Let name be the result of running percent-encode after encoding with encoding, tuple’s name, the application/x-www-form-urlencoded percent-encode set, and true. - auto name = TRY(URL::Parser::percent_encode_after_encoding(*encoder, tuple.name, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded, true)); + auto name = URL::Parser::percent_encode_after_encoding(*encoder, tuple.name, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded, true); // 3. Let value be the result of running percent-encode after encoding with encoding, tuple’s value, the application/x-www-form-urlencoded percent-encode set, and true. - auto value = TRY(URL::Parser::percent_encode_after_encoding(*encoder, tuple.value, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded, true)); + auto value = URL::Parser::percent_encode_after_encoding(*encoder, tuple.value, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded, true); // 4. If output is not the empty string, then append U+0026 (&) to output. if (!output.is_empty())