AK: Check URL parser input for invalid (tabs or spaces) in 1 pass

Combine 2 passes into 1 by iterating over the input once and checking
for both '\t' and '\n'.
This commit is contained in:
Andreas Kling 2023-12-29 18:33:10 +01:00
parent 7e2d9bfd53
commit 7ad7ae7000
Notes: sideshowbarker 2024-07-16 18:06:41 +09:00

View File

@ -796,9 +796,12 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
// 2. If input contains any ASCII tab or newline, invalid-URL-unit validation error.
// 3. Remove all ASCII tab or newline from input.
if (processed_input.contains("\t"sv) || processed_input.contains("\n"sv)) {
report_validation_error();
processed_input = processed_input.replace("\t"sv, ""sv, ReplaceMode::All).replace("\n"sv, ""sv, ReplaceMode::All);
for (auto const ch : processed_input) {
if (ch == '\t' || ch == '\n') {
report_validation_error();
processed_input = processed_input.replace("\t"sv, ""sv, ReplaceMode::All).replace("\n"sv, ""sv, ReplaceMode::All);
break;
}
}
// 4. Let state be state override if given, or scheme start state otherwise.