From 8cc2509c4aadf8c7dee1a1c63a125ce8b8c5a9ec Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Mon, 1 Jul 2024 00:33:01 -0700 Subject: [PATCH] Refactor `decodeEscapeSequencesFromParsedURLForWindowsPath` --- Source/WTF/wtf/URL.cpp | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Source/WTF/wtf/URL.cpp b/Source/WTF/wtf/URL.cpp index 4961de69faef8..cc65b19e07a63 100644 --- a/Source/WTF/wtf/URL.cpp +++ b/Source/WTF/wtf/URL.cpp @@ -234,13 +234,13 @@ static String decodeEscapeSequencesFromParsedURLForWindowsPath(const std::span percentDecodedUTF8; + percentDecodedUTF8.reserveInitialCapacity(length); + WTF::StringView inputView = input; + for (size_t i = input[0] == '/' ? 1 : 0; i < length; ) { + if (auto decodedCharacter = decodeEscapeSequence(inputView, i, length)) { + percentDecodedUTF8.append(*decodedCharacter); + i += 3; + } else if (input[i] != '/') { + percentDecodedUTF8.append(input[i]); + ++i; + } else { + percentDecodedUTF8.append('\\'); + ++i; + } + } + + return String::fromUTF8ReplacingInvalidSequences(percentDecodedUTF8.span()); } String URL::user() const