From 7ad7ae700062c8581b325e89fc6564f07f04570c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 29 Dec 2023 18:33:10 +0100 Subject: [PATCH] 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'. --- AK/URLParser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AK/URLParser.cpp b/AK/URLParser.cpp index c6e922f072..b4206683a4 100644 --- a/AK/URLParser.cpp +++ b/AK/URLParser.cpp @@ -796,9 +796,12 @@ URL URLParser::basic_parse(StringView raw_input, Optional 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.