Merge pull request #817 from lightpanda-io/script_tag_dump
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled

dump script tag's text content as-is
This commit is contained in:
Pierre Tachoire
2025-06-26 11:27:04 -07:00
committed by GitHub

View File

@@ -82,9 +82,13 @@ pub fn writeNode(node: *parser.Node, writer: anytype) anyerror!void {
// void elements can't have any content. // void elements can't have any content.
if (try isVoid(parser.nodeToElement(node))) return; if (try isVoid(parser.nodeToElement(node))) return;
if (try parser.elementHTMLGetTagType(@ptrCast(node)) == .script) {
try writer.writeAll(try parser.nodeTextContent(node) orelse "");
} else {
// write the children // write the children
// TODO avoid recursion // TODO avoid recursion
try writeChildren(node, writer); try writeChildren(node, writer);
}
// close the tag // close the tag
try writer.writeAll("</"); try writer.writeAll("</");
@@ -211,6 +215,11 @@ test "dump.writeHTML" {
\\</head><body>9000</body></html> \\</head><body>9000</body></html>
\\ \\
, "<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000"); , "<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000");
try testWriteHTML(
"<p>hi</p><script>alert(power > 9000)</script>",
"<p>hi</p><script>alert(power > 9000)</script>",
);
} }
fn testWriteHTML(comptime expected_body: []const u8, src: []const u8) !void { fn testWriteHTML(comptime expected_body: []const u8, src: []const u8) !void {