From 2abf36b80201e0c6e3d5c0bb04454029fc8a4777 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 13 Sep 2026 17:22:31 +0000 Subject: [PATCH 1/2] HTMLRewriter: reject every sequence that ends a comment in comment.text `comment.text = s` rejected `-->` only. The HTML tokenizer also ends a comment at `--!>`, and ends an empty comment at a leading `>` or `->`, so the rest of `s` left the comment and parsed as markup. Pin oven-sh/lol-html at ef9f6fd, a cherry-pick of upstream cloudflare/lol-html ba25359 (v3.0.0) onto the `bun` branch. `Comment::set_text` now returns `CommentClosingSequence` for all four forms. --- scripts/build/deps/lolhtml.ts | 2 +- test/js/workerd/html-rewriter.test.js | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/build/deps/lolhtml.ts b/scripts/build/deps/lolhtml.ts index 499ddf47ec7e..717ba5b7eb87 100644 --- a/scripts/build/deps/lolhtml.ts +++ b/scripts/build/deps/lolhtml.ts @@ -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 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 = { diff --git a/test/js/workerd/html-rewriter.test.js b/test/js/workerd/html-rewriter.test.js index 1c775108f01d..8f0c1104740a 100644 --- a/test/js/workerd/html-rewriter.test.js +++ b/test/js/workerd/html-rewriter.test.js @@ -2945,6 +2945,39 @@ describe("tagName, endTag.name, and comment.text setters", () => { expect(out).toBe("

A

"); }); + 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 = ""; + const setText = text => + new HTMLRewriter() + .on("p", { + comments(comment) { + comment.text = text; + }, + }) + .transform("

"); + + 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 `

`, and finds no other element. + const accepted = ["", "-", "--", "--!", "x--!", "x--", "a>b", "a->b", "a--!b", "x

`, comments: [text], elements: ["p"] }); + }); + }); + it("setters on a detached wrapper are a no-op and never coerce the value", () => { let savedElement; let savedEndTag; From 1678db9a664754e4efc62d9ff21ee341874b3236 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Tue, 22 Sep 2026 15:03:43 +0000 Subject: [PATCH 2/2] lolhtml: pin the comment.text fix on top of main's own lol-html commit a4a3d0c is 725ce49 (the commit main pins) plus the cherry-pick of cloudflare/lol-html ba25359, and nothing else. The earlier pin ef9f6fd also carried ea6125b (linear-depth descendant matching), which is a separate change with its own cost. --- scripts/build/deps/lolhtml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/deps/lolhtml.ts b/scripts/build/deps/lolhtml.ts index 219c5e0d64e2..731b2c4c4b81 100644 --- a/scripts/build/deps/lolhtml.ts +++ b/scripts/build/deps/lolhtml.ts @@ -25,7 +25,7 @@ import type { Dependency } from "../source.ts"; // base commit is recorded here so a rebase onto a new upstream tag is // `git rebase --onto bun` in the fork. const LOLHTML_UPSTREAM_BASE = "77127cd2b8545998756e8d64e36ee2313c4bb312"; // v2.7.2 -const LOLHTML_COMMIT = "ef9f6fd0de5eb1b4b7113aee14a21e5e6ba5e598"; +const LOLHTML_COMMIT = "a4a3d0ce7125b0334e7b481e6e2019232c66f2c0"; void LOLHTML_UPSTREAM_BASE; export const lolhtml: Dependency = {