Browse Source

LibWeb: Replace "+" in value with a space while decoding search params

Alisson Lauffer 11 months ago
parent
commit
d38b28b57b

+ 2 - 0
Tests/LibWeb/Text/expected/URL/search-params-with-plus-in-value.txt

@@ -0,0 +1,2 @@
+key 'key'
+value 'value1 value2'

+ 10 - 0
Tests/LibWeb/Text/input/URL/search-params-with-plus-in-value.html

@@ -0,0 +1,10 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        const params = new URLSearchParams('key=value1+value2');
+        for (const [key, value] of params) {
+            println(`key '${key}'`);
+            println(`value '${value}'`);
+        }
+    });
+</script>

+ 2 - 1
Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp

@@ -113,10 +113,11 @@ ErrorOr<Vector<QueryParam>> url_decode(StringView input)
 
 
         // 4. Replace any 0x2B (+) in name and value with 0x20 (SP).
         // 4. Replace any 0x2B (+) in name and value with 0x20 (SP).
         auto space_decoded_name = name.replace("+"sv, " "sv, ReplaceMode::All);
         auto space_decoded_name = name.replace("+"sv, " "sv, ReplaceMode::All);
+        auto space_decoded_value = value.replace("+"sv, " "sv, ReplaceMode::All);
 
 
         // 5. Let nameString and valueString be the result of running UTF-8 decode without BOM on the percent-decoding of name and value, respectively.
         // 5. Let nameString and valueString be the result of running UTF-8 decode without BOM on the percent-decoding of name and value, respectively.
         auto name_string = String::from_utf8_with_replacement_character(URL::percent_decode(space_decoded_name));
         auto name_string = String::from_utf8_with_replacement_character(URL::percent_decode(space_decoded_name));
-        auto value_string = String::from_utf8_with_replacement_character(URL::percent_decode(value));
+        auto value_string = String::from_utf8_with_replacement_character(URL::percent_decode(space_decoded_value));
 
 
         TRY(output.try_empend(move(name_string), move(value_string)));
         TRY(output.try_empend(move(name_string), move(value_string)));
     }
     }