LibWeb: Handle unpaired surrogates in USVStrings

This should fix (at least) the last two remaining WPT test failures in
FileAPI/unicode.html.
This commit is contained in:
justus2510 2024-10-13 03:52:16 +02:00 committed by Tim Ledbetter
commit 55f0dc823f
Notes: github-actions[bot] 2024-10-13 21:25:25 +00:00
3 changed files with 26 additions and 4 deletions

View file

@ -1414,19 +1414,23 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
}
bool includes_string = false;
RefPtr<IDL::Type const> string_type;
for (auto& type : types) {
if (type->is_string()) {
includes_string = true;
string_type = type;
break;
}
}
if (includes_string) {
if (string_type) {
// 14. If types includes a string type, then return the result of converting V to that type.
// NOTE: Currently all string types are converted to String.
IDL::Parameter parameter { .type = *string_type, .name = ByteString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, ByteString::formatted("{}{}_string", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
union_generator.append(R"~~~(
return TRY(@js_name@@js_suffix@.to_string(vm));
return { @js_name@@js_suffix@_string };
)~~~");
} else if (numeric_type && includes_bigint) {
// 15. If types includes a numeric type and bigint, then return the result of converting V to either that numeric type or bigint.

View file

@ -0,0 +1,2 @@
PASS
PASS

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest(async (done) => {
const unpairedSurrogates = "hello\uDC00friends\uD800:)";
const replacedSurrogates = "hello\uFFFDfriends\uFFFD:)";
const blob = new Blob([unpairedSurrogates]);
println(await blob.text() === replacedSurrogates ? "PASS" : "FAIL")
const file = new File([unpairedSurrogates], "someFileName");
println(await file.text() === replacedSurrogates ? "PASS" : "FAIL")
done();
});
</script>