From bf14d2f05c0a7e33fbfb6b0ec16471867ce247f9 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 26 Jun 2026 18:02:08 +0800 Subject: [PATCH] fix: Fix innerHTML parsing based on the target The parsing behavior of HTML depends on what we're parsing it for. innerHTML on a script is parsed (slightly) differently than for, say, the body. html5ever supports this, we just have to give it the tag name (which we have access to in the html5ever bridge already). Also, extend the tag types that dump does NOT escape for beyond noscript/script. Fixes warnings with some NextJS sites --- src/browser/dump.zig | 23 ++++++++++------ src/browser/parser/Parser.zig | 7 +++++ src/browser/parser/html5ever.zig | 2 ++ src/browser/tests/element/inner.html | 39 ++++++++++++++++++++++++++++ src/html5ever/lib.rs | 18 ++++++++++++- 5 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/browser/dump.zig b/src/browser/dump.zig index 90463c153..394e12c92 100644 --- a/src/browser/dump.zig +++ b/src/browser/dump.zig @@ -320,15 +320,22 @@ fn shouldStripElement(el: *Node.Element, opts: Opts, frame: *Frame) bool { } fn shouldEscapeText(node_: ?*Node) bool { + // Raw text elements serialize their text content literally rather than + // HTML-escaping it const node = node_ orelse return true; - if (node.is(Node.Element.Html.Script) != null) { - return false; - } - // When scripting is enabled,