From a204f4096803dc7bd60fd1ed542f3eb8828bc93b Mon Sep 17 00:00:00 2001 From: sjhddh Date: Sat, 14 Mar 2026 08:36:06 +0000 Subject: [PATCH] fix(dom): return parsererror document on XML parse failure --- src/browser/webapi/DOMParser.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/browser/webapi/DOMParser.zig b/src/browser/webapi/DOMParser.zig index 9e27e9c7..10a94bca 100644 --- a/src/browser/webapi/DOMParser.zig +++ b/src/browser/webapi/DOMParser.zig @@ -86,15 +86,15 @@ pub fn parseFromString( var parser = Parser.init(arena, doc_node, page); parser.parseXML(html); - if (parser.err) |pe| { - return pe.err; + if (parser.err != null or doc_node.firstChild() == null) { + // Return a document with a element per spec. + const err_doc = try page._factory.document(XMLDocument{ ._proto = undefined }); + var err_parser = Parser.init(arena, err_doc.asNode(), page); + err_parser.parseXML("error"); + return err_doc.asDocument(); } - const first_child = doc_node.firstChild() orelse { - // Empty XML or no root element - this is a parse error. - // TODO: Return a document with a element per spec. - return error.JsException; - }; + const first_child = doc_node.firstChild().?; // If first node is a `ProcessingInstruction`, skip it. if (first_child.getNodeType() == 7) {