Repository navigation
Conversation
Add the three onEndTag behavior tests from #31583 to test/js/workerd/html-rewriter.test.js. They cover endTag.before(), endTag.after() and endTag.remove(), an element whose end tag never appears, and the "No end tag." error for a void element. The tests pin behavior that main already has. They need no source change. Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
|
Status: the tests are pushed, with the review suggestions applied in 911fad5. CI runs now. How to verify: run |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. WalkthroughThe test suite adds coverage for ChangesHTML rewriter end-tag behavior
Suggested reviewers: Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The test-only change covers the intended HTML rewriter behaviors with observable assertions. No actionable merge risk remains. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
- Add a test for the html option of endTag.before() and endTag.after(). It uses markup as content, so escaped and raw output differ. - Add a test for an element that the end tag of its parent closes. The callback fires with that end tag. - Assert the class and the name of the "No end tag." error, not only its message. - Rename the unclosed element test. A callback can fire without the element's own end tag, so the old name was not exact.
|
Review follow-up: I checked the three optional suggestions against main and 1.3.14, and all three hold. 911fad5 applies them.
The threads have the details and are resolved. |
There was a problem hiding this comment.
LGTM — the second commit addresses each of the inline comments from the earlier review, and the new tests pin behavior the runtime already implements.
What was reviewed:
- The
{ html }option matrix now uses markup-bearing content (<b>Y</b>) for bothbeforeandafter, so the escaped vs. unescaped outputs are distinguishable; the expected strings matchcontent_type()in src/runtime/api/html_rewriter.rs (Html iffhtmlis truthy, Text otherwise). - The implicit-close case (
<section><div>b</section>) is now covered alongside the EOF-truncation case, asserting both output and the end tag name passed to the handler. - The void-element test asserts
toBeInstanceOf(Error)plus exactname/message, which matchcreate_lolhtml_error(HTMLRewriterError) and the"No end tag."throw at theend_tag_handlers()None branch.
Extended reasoning...
Overview
The PR adds five it(...) cases to the existing describe("HTMLRewriter") block in test/js/workerd/html-rewriter.test.js and touches no runtime code. The tests cover Element.onEndTag: before/after/remove on the end tag (including an unclosed trailing element), the { html } content-type option matrix for before and after, the negative contract that the callback does not fire when input ends before the element closes, the implicit-close case where a parent's </section> closes an open <div>, and the HTMLRewriterError / "No end tag." throw for a void element.
Security risks
None. The change is confined to a test file, uses in-process new Response(...) input, and makes no network or filesystem access.
Level of scrutiny
Low-to-moderate. Because no source changes ship, the relevant question is whether the tests are non-vacuous and pin the correct existing behavior. I checked the asserted values against the runtime: content_type() in src/runtime/api/html_rewriter.rs returns Html only when html is truthy, matching the six-entry matrix; create_lolhtml_error sets name to HTMLRewriterError on a plain Error, and on_end_tag_ throws "No end tag." when end_tag_handlers() is None (the void-element case). The void-element test captures the error inside the handler and asserts it after transform completes, so it fails if the handler does not run or does not throw. The implicit-close test asserts end.name is "section", consistent with lol-html invoking closed elements' end-tag handlers with the closing tag.
Other factors
All three inline comments from the prior review are addressed by commit 911fad5: markup-bearing content with both html states, the implicitly-closed variant, and class/name assertions on the error. The file's local conventions (it, module-scope imports, toEqual over a single object for the matrix) are followed. The changed path is not covered by .github/CODEOWNERS. I was unable to execute the test file in this environment, so the pass claim rests on the PR's stated bun bd test run plus CI; the static cross-check against the runtime source gives me confidence the expected values are correct.
Problem
element.onEndTag()behaviors:endTag.remove(), thehtmloption ofendTag.before()andendTag.after(), an element that is never closed, an element closed by the end tag of its parent, and theNo end tag.error for a void element.onEndTaghandler leak. HTMLRewriter: use the lol_html Rust crate directly instead of its C API #33048 fixed that leak in a different way, so htmlrewriter: release end-tag handler resources after each rewrite #31583 is closed and its tests did not land.Fix
test/js/workerd/html-rewriter.test.js, at the same place in the file. The commit credits the author.htmloption with markup as content, and an element closed by the end tag of its parent. The void element test also asserts the error class and name.bun bd test test/js/workerd/html-rewriter.test.js(191 pass, 0 fail).Background
element.onEndTag(fn)runsfnwhen an end tag closes that element.fnreceives anEndTagwithbefore(),after(),remove()andname.HTMLRewriter. If the input ends before an element is closed, the handler does not run. If the end tag of a parent closes the element, the handler runs with that end tag.<br>,<img>) cannot have an end tag.onEndTag()throws anErrornamedHTMLRewriterErrorfor it (src/runtime/api/html_rewriter.rs:3034).Notes
Coverage of
onEndTagon main before this PR:endTag.before(): only inside an async handler ("async onEndTag handler").endTag.after(): only withhtml: false, inside the "GC pressure mid-rewrite" test.endTag.remove(): none.Changes to the tests from #31583:
<section><div>b</section>the callback of thedivfires with thesectionend tag.instanceof Errorandname === "HTMLRewriterError"in addition to the message.Observed output for the
htmloption, the same on main and on 1.3.14:<div>a</div>zend.before("<b>Y</b>", { html: true })<div>a<b>Y</b></div>zend.before("<b>Y</b>")or{ html: false }<div>a<b>Y</b></div>zend.after("<b>Y</b>", { html: true })<div>a</div><b>Y</b>zend.after("<b>Y</b>")or{ html: false }<div>a</div><b>Y</b>zThe leak test from #31583 is not part of this PR.
test/js/workerd/html-rewriter-leak.test.tsalready has "onEndTag callbacks are released after the rewrite" from #33048, which counts protected callbacks exactly and also runs on debug builds.no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/workerd/html-rewriter.test.js