mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 09:18:55 +00:00
LibURL: Make percent_encode_after_encoding infallible
This commit is contained in:
parent
264b5160c2
commit
4bb211ba88
Notes:
github-actions[bot]
2024-08-12 22:02:40 +00:00
Author: https://github.com/shannonbooth
Commit: 4bb211ba88
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1033
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 8 additions and 8 deletions
|
@ -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;
|
||||||
|
|
|
@ -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&);
|
||||||
|
|
|
@ -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())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue