mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-10-26 06:49:12 +03:00
LibWeb: Allow splitting surrogate pairs in CharacterData.replaceData()
We're expected to handle this situation gracefully, and certainly not by falling apart like we were. Found by Domato.
This commit is contained in:
parent
416c478876
commit
33207174a9
Notes:
github-actions[bot]
2024-07-20 04:41:59 +00:00
Author: https://github.com/awesomekling 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/33207174a9 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/721
@ -0,0 +1,5 @@
|
||||
Before replaceData:
|
||||
[0]: 53997
|
||||
[1]: 56998
|
||||
After replaceData:
|
||||
[0]: 56998
|
@ -0,0 +1,16 @@
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const str = '\uD2ED\uDEA6';
|
||||
let t = document.createTextNode(str);
|
||||
println("Before replaceData:");
|
||||
for (let i = 0; i < t.length; ++i) {
|
||||
println("[" + i + "]: " + t.data.charCodeAt(i));
|
||||
}
|
||||
t.replaceData(0, 1, '')
|
||||
println("After replaceData:");
|
||||
for (let i = 0; i < t.length; ++i) {
|
||||
println("[" + i + "]: " + t.data.charCodeAt(i));
|
||||
}
|
||||
});
|
||||
</script>
|
@ -87,9 +87,9 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
|
||||
// 6. Let delete offset be offset + data’s length.
|
||||
// 7. Starting from delete offset code units, remove count code units from node’s data.
|
||||
StringBuilder builder;
|
||||
builder.append(MUST(utf16_view.substring_view(0, offset).to_utf8()));
|
||||
builder.append(MUST(utf16_view.substring_view(0, offset).to_utf8(Utf16View::AllowInvalidCodeUnits::Yes)));
|
||||
builder.append(data);
|
||||
builder.append(MUST(utf16_view.substring_view(offset + count).to_utf8()));
|
||||
builder.append(MUST(utf16_view.substring_view(offset + count).to_utf8(Utf16View::AllowInvalidCodeUnits::Yes)));
|
||||
m_data = MUST(builder.to_string());
|
||||
|
||||
// 8. For each live range whose start node is node and start offset is greater than offset but less than or equal to offset plus count, set its start offset to offset.
|
||||
|
Loading…
Reference in New Issue
Block a user