Skip to content

fix: output-check reports name the component and see forms the way the browser does - #309

Merged
JuroOravec merged 2 commits into
mainfrom
fix/output-check-component-and-form
Oct 24, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/output-check-component-and-form

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Fixes #290.

What changes

With security_csp or security_javascript set, serialize() reports
what the finished page holds. Two parts of those reports were wrong for
any element that is not a component's outermost tag:

  • The finding named the wrong owner. A component was named only when
    the reported element itself carried the component's data-cid-*
    attribute, so anything nested inside a component's outer tag was
    reported as "settled render output". Now the report names the innermost
    component whose outer element contains the reported element in the
    page the browser builds. Content passed into a slot is reported under
    the component that renders the slot.
  • omit mode misreported a control inside a form. A submit button, an
    input, a select or a textarea inside a <form> was reported as
    having no fallback, although the browser can submit the form without
    JavaScript. Now it is not. A type="button" button and an input of
    type button or reset are still reported, because they never submit.

How

The output check already reads the page with html5ever's tree builder. It
now also reads where the tree builder put each element:

  • A small DOM sink (TrackingSink in
    crates/citry_html_transform/src/output_scanner.rs) records the element
    each start tag makes, and whether the parser tied it to the form its
    form pointer names (the last <form> not yet closed by </form>;
    html5ever calls associate_with_form for this, so a control in a table
    inside a form counts too, as in the browser).
  • For an event, the check walks that element's parents in the tree. The
    event's cids list the element's own data-cid-* suffixes, then those
    of the elements that contain it, nearest first. Python already names the
    first known one, so the binding's tuple shape is unchanged; only its docs and
    _rust.pyi say what the list now holds.
  • The parser keeps a <template>'s children in a separate fragment with
    no parent. The sink points that fragment at its template, so an element
    inside <template v-if> still reaches the component around it.
  • Inside <svg> the parser spells some names with capitals
    (foreignObject), so the sink matches the element name without regard
    to case.
  • An HTML control counts as owned by a form when the parser tied it to one,
    or, as the browser decides for a control the parser did not tie, when a
    <form> contains it. The second case covers <form><div></form> with
    a later button inside the <div>. A form outside a <template> does
    not own what is inside the template, and a <button> inside <svg> is
    not a control. is_handler_only_control uses this next to the form
    attribute.

Known limit: the owner and the component ids are read when the parser
inserts the element. The parser can still move an element later when it
repairs a misnested formatting tag. For example, in
<b><form><div></form><button>...</b> the </b> moves the <div> out
of the form, so in the browser the button ends with no owner, but the
check counts the form. A Rust test records this answer so a later fix
changes it on purpose.

Because the positions come from the tree the browser builds, implied end
tags (<p> closed by <div>, a second <li>), misnested tags and foster
parenting place elements the way the browser does. For example, a link
inside <p>…<div> is not named after the <p>'s component, because the
<div> closed the <p>.

The walk runs only for tags that produce an event, so a clean page costs
one recorded pointer per tag.

How it was checked

  • Rust unit tests on the parent walk: nested components (innermost first),
    SVG content, an SVG element with a capitalized name, an element inside
    a <template> and inside nested templates, a <p> closed by <div>, a second <li>, a closed
    component followed by a link, a link the parser moves out before a
    table, a misnested </b>; and form cases: a button, an input, a
    select and a textarea inside a form, a button in a table inside a
    form, a button with a form attribute, and, still reported, a button
    outside any form, one after its form closed, a type=button, and one
    inside a <template> inside a form, and an SVG <button> inside a
    form. Also with a fallback: a button inside a form inside a template, a button
    after a </form> that left its <div> open (the browser gives it the
    form that contains it), and one after <div><form></div> (the form
    pointer still ties it to the form).

  • Python end-to-end tests serialize crafted components: a finding inside
    a component's root, inside a nested component, in slot content (named
    after the component that renders the slot), a link moved out of a
    component's root by an implied close, a submit button inside a form, and
    a button after its form closed.

  • The frozen Python copy of the rules reads a flat list of tags, so it
    cannot see the tree. The differential comparison (seeded pages, and the
    opt-in whole-suite run) goes through outcomes_match in
    packages/py/citry/tests/_output_policy_reference.py. It allows only the
    two differences this PR makes on purpose, and each in one direction:

    1. Component name. When the copy names a known component, Rust must
      name the same one. Only when the copy names no component may Rust
      name one.
    2. Handler-only findings on controls a form can submit (a button
      that is not type=button, an input that is not type button or
      reset, a select, a textarea). Rust may leave such a finding
      out, because the copy cannot see the form, but only when a <form>
      start tag comes earlier in the page. Rust may not add one.

    Everything else must match in both directions and in order: every other
    finding (rule, detail, attribute, offsets), the result, the report
    lines, and whether the check warns or raises. A report header's count
    is checked against its own lines, and a warning may disappear only when
    every line in it is one Rust may leave out. This is stricter than
    masking both sides, which would also accept a wrong name on an
    element's own data-cid-* or an extra Rust finding. Two mistakes would
    still pass this comparison: a wrong ancestor component for an element
    with no data-cid-* of its own, and a handler-only finding left out for
    a control that is not really in a form. The Rust unit tests and the
    end-to-end tests above cover those. A throwaway harness confirmed that
    outcomes_match rejects a dropped type=button finding, an added
    finding, a reordered pair, and a renamed known component.

  • Existing locked messages that changed (findings nested inside a
    component's root now name it) were updated from the observed output.

  • The whole-suite run with CITRY_OUTPUT_POLICY_DIFFERENTIAL=1 (the
    citry and citry-ui suites) passed 11,466 tests. 3 tests failed, and none
    of them involve this change: they make the Python tag reader or the
    Rust call fail on purpose. The second commit in this PR (test-only) skips
    those 3 tests when the flag is set. Without the flag they run and pass
    as before.

  • The fast gate (scripts/check.py --profile fast) passed.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 24, 2026 13:21
…rol's form as its fallback

The strict-CSP and JavaScript-policy reports named a component only when
the reported element itself carried a data-cid attribute, so a finding
inside a component's outer element said "settled render output". In
omit mode the check also did not know that a control sits inside a
<form>, so a submit button there was reported as having no fallback.

The output check now reads where the browser put each element from the
tree the HTML parser builds. Citry's receiver for the parser's tree
(TrackingSink) records the element each start tag makes and whether the
parser tied it to the form its form pointer names (the last <form> not
yet closed by </form>). Each finding's list of component ids (cids) holds the element's own data-cid suffixes, then
those of the elements that contain it, nearest first, so Python names
the innermost known component with no change to the binding's shape.
The walk also steps from a <template>'s children to the template, and it
matches SVG names that the parser spells with capitals. An HTML control
counts as owned by a form when the parser tied it to one, or, as in the
browser, when a <form> contains it outside a template's contents; the
handler-only rule uses that. Both answers are read when the parser
inserts the element, so a later move by the parser's repair of a
misnested formatting tag is not seen; a test records that limit. Implied end tags, misnested tags and tables
move elements the way they move in the browser.

The frozen Python copy reads a flat list of tags, so the differential
comparison (outcomes_match) allows exactly two differences: Rust may
name a component where the copy names none, and Rust may leave out a
handler-only finding on a control that a form earlier in the page can
submit. Every other finding, message, order, offset and warn-or-raise
outcome must match. A report header's count is checked against its own
lines, because a left-out finding changes it.

New tests cover nested components, slot content, implied and misnested
closes, tables, SVG, templates, a button inside a form, one after its
form closed, one after a </form> that left its <div> open, one inside a
<template> inside a form, and an SVG <button> inside a form.

Fixes #290.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e side

Three tests in test_output_policy.py make the Python tag reader or the
Rust call fail on purpose, so with CITRY_OUTPUT_POLICY_DIFFERENTIAL=1
the comparison with the frozen Python rules reported that failure as a
difference. They now skip when that flag is set, and run as before
without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 25595af into main Oct 24, 2026
33 checks passed
@JuroOravec
JuroOravec deleted the fix/output-check-component-and-form branch October 24, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output checks name "settled render output" instead of the component, and miss a surrounding <form>

1 participant