don't escape noscript content on html dump

This commit is contained in:
Pierre Tachoire
2026-02-24 15:21:55 +01:00
parent ca2df83928
commit 1d8e0629af
2 changed files with 30 additions and 0 deletions

View File

@@ -294,6 +294,12 @@ fn shouldEscapeText(node_: ?*Node) bool {
if (node.is(Node.Element.Html.Script) != null) {
return false;
}
// When scripting is enabled, <noscript> is a raw text element per the HTML spec
// (https://html.spec.whatwg.org/multipage/parsing.html#serialising-html-fragments).
// Its text content must not be HTML-escaped during serialization.
if (node.is(Node.Element.Html.Generic)) |generic| {
if (generic._tag == .noscript) return false;
}
return true;
}
fn writeEscapedText(text: []const u8, writer: *std.Io.Writer) !void {

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<script src="../testing.js"></script>
<!-- When scripting is enabled the HTML parser treats <noscript> as a raw text
element: its entire content is stored as a single text node containing the
raw markup. Serializing it back (outerHTML / innerHTML) must output that
markup as-is without HTML-escaping the angle brackets. -->
<noscript id="ns1"><h1>Hello</h1><p>World</p></noscript>
<noscript id="ns2"><div id="bsky_post_summary"><h3>Post</h3><p id="bsky_display_name">Henri Helvetica</p></div></noscript>
<script id="noscript-outerHTML">
const ns1 = document.getElementById('ns1');
testing.expectEqual('<noscript id="ns1"><h1>Hello</h1><p>World</p></noscript>', ns1.outerHTML);
</script>
<script id="noscript-innerHTML">
const ns2 = document.getElementById('ns2');
testing.expectEqual('<div id="bsky_post_summary"><h3>Post</h3><p id="bsky_display_name">Henri Helvetica</p></div>', ns2.innerHTML);
</script>
<script id="noscript-textContent">
// The raw text node content must be the literal HTML markup (not parsed DOM)
testing.expectEqual('<h1>Hello</h1><p>World</p>', ns1.firstChild.nodeValue);
</script>