Ver código fonte

LibURL: Make percent_encode_after_encoding infallible

Shannon Booth 1 ano atrás
pai
commit
4bb211ba88

+ 5 - 5
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
 // https://url.spec.whatwg.org/#string-percent-encode-after-encoding
-ErrorOr<String> 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.
     // 1. Let encodeOutput be an empty I/O queue.
     StringBuilder output;
     StringBuilder output;
 
 
     // 2. Set potentialError to the result of running encode or fail with inputQueue, encoder, and encodeOutput.
     // 2. Set potentialError to the result of running encode or fail with inputQueue, encoder, and encodeOutput.
-    TRY(encoder.process(
+    MUST(encoder.process(
         Utf8View(input),
         Utf8View(input),
 
 
         // 3. For each byte of encodeOutput converted to a byte sequence:
         // 3. For each byte of encodeOutput converted to a byte sequence:
@@ -813,7 +813,7 @@ ErrorOr<String> Parser::percent_encode_after_encoding(TextCodec::Encoder& encode
         }));
         }));
 
 
     // 6. Return output.
     // 6. Return output.
-    return output.to_string();
+    return MUST(output.to_string());
 }
 }
 
 
 // https://url.spec.whatwg.org/#concept-basic-url-parser
 // https://url.spec.whatwg.org/#concept-basic-url-parser
@@ -1703,7 +1703,7 @@ URL Parser::basic_parse(StringView raw_input, Optional<URL> const& base_url, Opt
                 auto query_percent_encode_set = url->is_special() ? PercentEncodeSet::SpecialQuery : PercentEncodeSet::Query;
                 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.
                 // 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.
                 // 3. Set buffer to the empty string.
                 buffer.clear();
                 buffer.clear();
@@ -1745,7 +1745,7 @@ URL Parser::basic_parse(StringView raw_input, Optional<URL> const& base_url, Opt
                 // NOTE: The percent-encode is done on EOF on the entire buffer.
                 // NOTE: The percent-encode is done on EOF on the entire buffer.
                 buffer.append_code_point(code_point);
                 buffer.append_code_point(code_point);
             } else {
             } 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();
                 buffer.clear();
             }
             }
             break;
             break;

+ 1 - 1
Userland/Libraries/LibURL/Parser.h

@@ -61,7 +61,7 @@ public:
     static URL basic_parse(StringView input, Optional<URL> const& base_url = {}, Optional<URL> url = {}, Optional<State> state_override = {}, Optional<StringView> encoding = {});
     static URL basic_parse(StringView input, Optional<URL> const& base_url = {}, Optional<URL> url = {}, Optional<State> state_override = {}, Optional<StringView> encoding = {});
 
 
     // https://url.spec.whatwg.org/#string-percent-encode-after-encoding
     // https://url.spec.whatwg.org/#string-percent-encode-after-encoding
-    static ErrorOr<String> 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
     // https://url.spec.whatwg.org/#concept-host-serializer
     static ErrorOr<String> serialize_host(Host const&);
     static ErrorOr<String> serialize_host(Host const&);

+ 2 - 2
Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp

@@ -62,10 +62,10 @@ ErrorOr<String> url_encode(Vector<QueryParam> const& tuples, StringView encoding
         // 1. Assert: tuple’s name and tuple’s value are scalar value strings.
         // 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.
         // 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.
         // 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.
         // 4. If output is not the empty string, then append U+0026 (&) to output.
         if (!output.is_empty())
         if (!output.is_empty())