Skip to content

Commit

Permalink
fix document.close() inject to only be used for JS scripts (#141)
Browse files Browse the repository at this point in the history
fixes webrecorder/archiveweb.page#178
bump to 2.16.9
  • Loading branch information
ikreymer authored Aug 17, 2023
1 parent 8a6ca2e commit bc4f5d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webrecorder/wabac",
"version": "2.16.8",
"version": "2.16.9",
"main": "index.js",
"type": "module",
"license": "AGPL-3.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class HTMLRewriter
break;

case "script":
if (headDone && !isTextEmpty) {
if (headDone && !isTextEmpty && (!scriptRw || scriptRw === "js")) {
rwStream.emitRaw(";document.close();");
}
break;
Expand Down
6 changes: 6 additions & 0 deletions test/rewriteHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ test("script", rewriteHtml,
<script>var foo = x;;document.close();</script>
</body>`);

// SCRIPT tag in body but json
test("script", rewriteHtml,
"<body><script type=\"application/json\">{\"embed top test\": \"http://example.com/a/b/c.html\"}</script></body>",
"<body><script type=\"application/json\">{\"embed top test\": \"http://example.com/a/b/c.html\"}</script></body>"
);

// SCRIPT tag ensure reset after known type
test("script", rewriteHtml,
`<script type="application/javascript">document.location.href = "abc";</script>
Expand Down

0 comments on commit bc4f5d2

Please sign in to comment.