Skip to content

Commit ed7dfea

Browse files
committed
dump script tag's text content as-is
1 parent 8de27b3 commit ed7dfea

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/browser/dump.zig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ pub fn writeNode(node: *parser.Node, writer: anytype) anyerror!void {
8282
// void elements can't have any content.
8383
if (try isVoid(parser.nodeToElement(node))) return;
8484

85-
// write the children
86-
// TODO avoid recursion
87-
try writeChildren(node, writer);
85+
if (try parser.elementHTMLGetTagType(@ptrCast(node)) == .script) {
86+
try writer.writeAll(try parser.nodeTextContent(node) orelse "");
87+
} else {
88+
// write the children
89+
// TODO avoid recursion
90+
try writeChildren(node, writer);
91+
}
8892

8993
// close the tag
9094
try writer.writeAll("</");
@@ -211,6 +215,11 @@ test "dump.writeHTML" {
211215
\\</head><body>9000</body></html>
212216
\\
213217
, "<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000");
218+
219+
try testWriteHTML(
220+
"<p>hi</p><script>alert(power > 9000)</script>",
221+
"<p>hi</p><script>alert(power > 9000)</script>",
222+
);
214223
}
215224

216225
fn testWriteHTML(comptime expected_body: []const u8, src: []const u8) !void {

0 commit comments

Comments
 (0)