From b118c99c271e34e2c5020022d062a4371f199a71 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 Jun 2024 19:34:53 +0200 Subject: [PATCH] LibWeb: Add null check in Document::ancestor_navigables() The spec doesn't explicitly forbid calling this when the document doesn't have a node navigable, so let's handle that situation gracefully by just returning an empty list of ancestors. I hit this VERIFY somewhere on the web, but I don't know how to reproduce it. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 3d0418c1b1d..3343662ea97 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -3063,9 +3063,13 @@ Vector> Document::inclusive_descendant_navigables() // https://html.spec.whatwg.org/multipage/document-sequences.html#ancestor-navigables Vector> Document::ancestor_navigables() { + // NOTE: This isn't in the spec, but if we don't have a navigable, we can't have ancestors either. + auto document_node_navigable = this->navigable(); + if (!document_node_navigable) + return {}; + // 1. Let navigable be document's node navigable's parent. - VERIFY(navigable()); - auto navigable = this->navigable()->parent(); + auto navigable = document_node_navigable->parent(); // 2. Let ancestors be an empty list. Vector> ancestors;