mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-15 23:09:05 +00:00
LibWeb: Allow splitting surrogate pairs in CharacterData.substringData()
This commit is contained in:
parent
0b775da7c7
commit
b999f925dc
Notes:
github-actions[bot]
2024-10-20 10:19:54 +00:00
Author: https://github.com/shannonbooth
Commit: b999f925dc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1875
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 25 additions and 2 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
Before substringData:
|
||||||
|
[0]: 55357
|
||||||
|
[1]: 56374
|
||||||
|
After substringData(0, 1):
|
||||||
|
[0]: 55357
|
|
@ -0,0 +1,18 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const str = '\uD83D\uDC36'; // 🐶
|
||||||
|
let t = document.createTextNode(str);
|
||||||
|
println("Before substringData:");
|
||||||
|
for (let i = 0; i < t.length; ++i) {
|
||||||
|
println("[" + i + "]: " + t.data.charCodeAt(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Break the surrogate pair
|
||||||
|
const invalidSubstring = t.substringData(0, 1);
|
||||||
|
println("After substringData(0, 1):");
|
||||||
|
for (let i = 0; i < invalidSubstring.length; ++i) {
|
||||||
|
println("[" + i + "]: " + invalidSubstring.charCodeAt(i));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -57,10 +57,10 @@ WebIDL::ExceptionOr<String> CharacterData::substring_data(size_t offset, size_t
|
||||||
// 3. If offset plus count is greater than length, return a string whose value is the code units from the offsetth code unit
|
// 3. If offset plus count is greater than length, return a string whose value is the code units from the offsetth code unit
|
||||||
// to the end of node’s data, and then return.
|
// to the end of node’s data, and then return.
|
||||||
if (offset + count > length)
|
if (offset + count > length)
|
||||||
return MUST(utf16_view.substring_view(offset).to_utf8());
|
return MUST(utf16_view.substring_view(offset).to_utf8(Utf16View::AllowInvalidCodeUnits::Yes));
|
||||||
|
|
||||||
// 4. Return a string whose value is the code units from the offsetth code unit to the offset+countth code unit in node’s data.
|
// 4. Return a string whose value is the code units from the offsetth code unit to the offset+countth code unit in node’s data.
|
||||||
return MUST(utf16_view.substring_view(offset, count).to_utf8());
|
return MUST(utf16_view.substring_view(offset, count).to_utf8(Utf16View::AllowInvalidCodeUnits::Yes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-cd-replace
|
// https://dom.spec.whatwg.org/#concept-cd-replace
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue