forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Don't crash on live range offset update during node insertion
When inserting a node into a parent, any live DOM ranges that reference the parent may need to be updated. The spec does this by increasing or decreasing the start/end offsets of each live range *before* actually performing the insertion. This caused us to crash with a verification failure, since it was possible to set the range offset to an invalid value (that would go on to immediately become valid after the insertion was finished). This patch fixes the issue by adding special badged helpers on Range for Node to reach into it and increase/decrease the offsets during node insertion. This skips the offset validity check and actually makes our code read slightly more like the spec. Found by Domato :^)
- Loading branch information
1 parent
a98b229
commit 8e00e7f
Showing
5 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
Tests/LibWeb/Text/expected/DOM/update-live-ranges-on-node-insertion.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1 | ||
<H2 > | ||
2 | ||
<H2 > | ||
2 |
14 changes: 14 additions & 0 deletions
14
Tests/LibWeb/Text/input/DOM/update-live-ranges-on-node-insertion.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script src="../include.js"></script> | ||
<script> | ||
test(() => { | ||
const h2 = document.querySelector("h2"); | ||
document.getSelection().collapse(h2, 1); | ||
var h3 = document.createElement("h3"); | ||
h2.insertBefore(h3, h2.firstChild) | ||
println(document.getSelection().rangeCount); | ||
printElement(document.getSelection().getRangeAt(0).startContainer); | ||
println(document.getSelection().getRangeAt(0).startOffset); | ||
printElement(document.getSelection().getRangeAt(0).endContainer); | ||
println(document.getSelection().getRangeAt(0).endOffset); | ||
}); | ||
</script><h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters