mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-05 09:52:54 +00:00
LibURL: Allow inputs containing only whitespace
The check for: ``` if (start_index >= end_index) return {}; ``` To prevent an out of bounds when trimming the start and end of the input of whitespace was preventing valid URLs (only having whitespace in the input) from being parsed. Instead, prevent start_index from ever getting above end_index in the first place, and don't treat empty inputs as an error. Fixes one WPT test on: https://wpt.live/url/url-constructor.any.html
This commit is contained in:
parent
4f5af3e90e
commit
d6af5bf5eb
Notes:
github-actions[bot]
2024-08-05 16:22:19 +00:00
Author: https://github.com/shannonbooth
Commit: d6af5bf5eb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/973
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 30 additions and 16 deletions
|
@ -808,29 +808,22 @@ URL Parser::basic_parse(StringView raw_input, Optional<URL> const& base_url, Opt
|
|||
// 2. If input contains any leading or trailing C0 control or space, invalid-URL-unit validation error.
|
||||
// 3. Remove any leading and trailing C0 control or space from input.
|
||||
bool has_validation_error = false;
|
||||
for (size_t i = 0; i < raw_input.length(); ++i) {
|
||||
u8 ch = raw_input[i];
|
||||
if (is_ascii_c0_control_or_space(ch)) {
|
||||
++start_index;
|
||||
has_validation_error = true;
|
||||
} else {
|
||||
|
||||
for (; start_index < raw_input.length(); ++start_index) {
|
||||
if (!is_ascii_c0_control_or_space(raw_input[start_index]))
|
||||
break;
|
||||
}
|
||||
has_validation_error = true;
|
||||
}
|
||||
for (ssize_t i = raw_input.length() - 1; i >= 0; --i) {
|
||||
u8 ch = raw_input[i];
|
||||
if (is_ascii_c0_control_or_space(ch)) {
|
||||
--end_index;
|
||||
has_validation_error = true;
|
||||
} else {
|
||||
|
||||
for (; end_index > start_index; --end_index) {
|
||||
if (!is_ascii_c0_control_or_space(raw_input[end_index - 1]))
|
||||
break;
|
||||
}
|
||||
has_validation_error = true;
|
||||
}
|
||||
|
||||
if (has_validation_error)
|
||||
report_validation_error();
|
||||
}
|
||||
if (start_index >= end_index)
|
||||
return {};
|
||||
|
||||
ByteString processed_input = raw_input.substring_view(start_index, end_index - start_index);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue