LibWeb: Use UTF-16 code units length in CharacterData::replace_data()

Range API uses UTF-16 code units to represent offsets, so replace_data()
needs to use it instead of bytes count while calculating new offsets.

Fixes incorrectly thrown exception when non-latin string is passed into
replace_data().
This commit is contained in:
Aliaksandr Kalenik 2024-11-06 04:26:56 +01:00 committed by Tim Ledbetter
commit 42b31820a6
Notes: github-actions[bot] 2024-11-06 05:47:30 +00:00
3 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<script src="include.js"></script>
<div id="text">==</div>
<script>
test(() => {
const text = document.getElementById("text");
const range = document.createRange();
range.setStart(text.firstChild, 0);
range.setEnd(text.firstChild, text.firstChild.length);
text.firstChild.insertData(1, "Привет");
println(range.toString());
});
</script>