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:
Andreas Kling 2024-07-19 20:02:14 +02:00 committed by Andreas Kling
commit 33207174a9
Notes: github-actions[bot] 2024-07-20 04:41:59 +00:00
3 changed files with 23 additions and 2 deletions

View file

@ -87,9 +87,9 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
// 6. Let delete offset be offset + datas length.
// 7. Starting from delete offset code units, remove count code units from nodes 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.