Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/build/deps/lolhtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { Dependency } from "../source.ts";
// base commit is recorded here so a rebase onto a new upstream tag is
// `git rebase --onto <new-tag> <LOLHTML_UPSTREAM_BASE> bun` in the fork.
const LOLHTML_UPSTREAM_BASE = "77127cd2b8545998756e8d64e36ee2313c4bb312"; // v2.7.2
const LOLHTML_COMMIT = "725ce499aa9b71e38b7a2d0a9fbb6d7294a4079e";
const LOLHTML_COMMIT = "ef9f6fd0de5eb1b4b7113aee14a21e5e6ba5e598";
void LOLHTML_UPSTREAM_BASE;

export const lolhtml: Dependency = {
Expand Down
33 changes: 33 additions & 0 deletions test/js/workerd/html-rewriter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2945,6 +2945,39 @@ describe("tagName, endTag.name, and comment.text setters", () => {
expect(out).toBe("<p>A<!--B--></p>");
});

describe("comment.text and the sequences that end a comment", () => {
// The tokenizer ends a comment at `-->` and at `--!>` anywhere in its text,
// and at a leading `>` or `->` (`<!-->` and `<!--->` are empty comments).
// Anything after one of these is outside the comment, so it is markup.
const markup = "<img src=x onerror=alert(1)>";
const setText = text =>
new HTMLRewriter()
.on("p", {
comments(comment) {
comment.text = text;
},
})
.transform("<p><!--c--></p>");

it.each(["x-->", "x--!>", ">", "->"].flatMap(end => [end, end + markup]))("%j is rejected", text => {
expect(() => setText(text)).toThrow("Comment text shouldn't contain a comment-closing sequence.");
});

// Text that only resembles one of them stays valid: a second parse reads it
// back as the one comment inside `<p>`, and finds no other element.
const accepted = ["", "-", "--", "--!", "x--!", "x--", "a>b", "a->b", "a--!b", "x<!--", "x" + markup];
it.each(accepted)("%j is accepted", text => {
const out = setText(text);
const comments = [];
const elements = [];
new HTMLRewriter()
.onDocument({ comments: comment => void comments.push(comment.text) })
.on("*", { element: el => void elements.push(el.tagName) })
.transform(out);
expect({ out, comments, elements }).toEqual({ out: `<p><!--${text}--></p>`, comments: [text], elements: ["p"] });
});
});

it("setters on a detached wrapper are a no-op and never coerce the value", () => {
let savedElement;
let savedEndTag;
Expand Down
Loading