mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibWeb: Don't crash when updating a select with detached option elements
`Node::shadow_including_root()` was missing a null check, which caused a crash when manipulating a select element, whose option elements were initially detached.
This commit is contained in:
parent
521a1be97f
commit
2227674b91
Notes:
sideshowbarker
2024-07-17 08:55:54 +09:00
Author: https://github.com/tcl3
Commit: 2227674b91
Pull-request: https://github.com/SerenityOS/serenity/pull/23687
Reviewed-by: https://github.com/awesomekling
3 changed files with 18 additions and 2 deletions
|
@ -0,0 +1 @@
|
|||
PASS (didn't crash)
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<select></select>
|
||||
<script>
|
||||
test(() => {
|
||||
const selectElement = document.querySelector("select");
|
||||
const optionElement = document.createElement("option");
|
||||
optionElement.innerHTML = "option text"
|
||||
selectElement.appendChild(optionElement);
|
||||
document.body.removeChild(selectElement);
|
||||
println("PASS (didn't crash)");
|
||||
});
|
||||
</script>
|
|
@ -320,8 +320,10 @@ Node& Node::shadow_including_root()
|
|||
// The shadow-including root of an object is its root’s host’s shadow-including root,
|
||||
// if the object’s root is a shadow root; otherwise its root.
|
||||
auto& node_root = root();
|
||||
if (is<ShadowRoot>(node_root))
|
||||
return static_cast<ShadowRoot&>(node_root).host()->shadow_including_root();
|
||||
if (is<ShadowRoot>(node_root)) {
|
||||
if (auto* host = static_cast<ShadowRoot&>(node_root).host(); host)
|
||||
return host->shadow_including_root();
|
||||
}
|
||||
return node_root;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue