mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Actually run UTF-8 decode without BOM
This fixes a crash using URLSearchParams when provided a percent encoded string which does not percent decode to valid UTF-8. Fixes a crash running https://wpt.live/url/urlencoded-parser.any.html
This commit is contained in:
parent
033ea0e7fb
commit
9c72fc9642
Notes:
github-actions[bot]
2024-08-10 08:47:22 +00:00
Author: https://github.com/shannonbooth
Commit: 9c72fc9642
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1023
Reviewed-by: https://github.com/awesomekling
3 changed files with 14 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
key equals = true
|
||||||
|
value equals = true
|
|
@ -0,0 +1,10 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const params = new URLSearchParams('%FE%FF');
|
||||||
|
for (const [key, value] of params) {
|
||||||
|
println(`key equals = ${"\uFFFD\uFFFD" === key}`);
|
||||||
|
println(`value equals = ${"" === value}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -115,8 +115,8 @@ ErrorOr<Vector<QueryParam>> url_decode(StringView input)
|
||||||
auto space_decoded_name = name.replace("+"sv, " "sv, ReplaceMode::All);
|
auto space_decoded_name = name.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 = TRY(String::from_byte_string(URL::percent_decode(space_decoded_name)));
|
auto name_string = String::from_utf8_with_replacement_character(URL::percent_decode(space_decoded_name));
|
||||||
auto value_string = TRY(String::from_byte_string(URL::percent_decode(value)));
|
auto value_string = String::from_utf8_with_replacement_character(URL::percent_decode(value));
|
||||||
|
|
||||||
TRY(output.try_empend(move(name_string), move(value_string)));
|
TRY(output.try_empend(move(name_string), move(value_string)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue