Skip to content

fix(html): read a repeated attribute as its first value in the output checks - #674

Merged
JuroOravec merged 1 commit into
mainfrom
fix/citry-ui-validator-attrs
Nov 14, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/citry-ui-validator-attrs

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

What changes

A browser keeps the first of two attributes with the same name on one tag: <div a="1" a="2"> has a="1". Several Citry UI components check the HTML they receive as slot content (a fill) after it renders. They read each tag's attributes with dict(attrs), which keeps the last value for a repeated name, so a check could judge a tag by a value the browser ignores. This PR makes them read repeated attributes as the browser does, and fixes two smaller problems found while reviewing #610.

  • First value wins. LongReferenceSafeParser (citry/util/html.py) is the HTMLParser subclass that Citry's checks of rendered HTML build on. It now gives a subclass's start tag handler one entry per attribute name, with the first value. Only subclasses that read attribute values get this. That covers the development warning for a repeated id (_page_ids.py) and the check that finds the element Vue mounts on (_vue/serialization.py). The Citry UI checks (CDisclosure, CImage, CListbox, CTree, CCommandPalette) also call their own first_attribute_occurrences (citry_ui/components/_validation.py). Citry UI declares citry>=0.7.0, and Citry releases before 0.9.0 give a handler every occurrence of a repeated name.
  • A long reference split after & no longer fails. The parser reads a page in chunks, and rewrites a numeric character reference with thousands of digits before Python converts it. A chunk that ended right after the & hid the reference from that rewrite, and ValueError followed. The parser now waits for the next chunk when a chunk ends in a lone &, as it already did for &# and digits. The error made Citry skip its preload links for such a page.
  • Tag names in error messages. A tag name in rendered HTML can hold a control character, and an ESC in an error message would reach the developer's terminal. The Citry UI check messages now write such characters as escapes, such as \x1b.
  • Changelog. The Citry UI changelog gets the entry Read numeric references in attribute values as the browser does #610 left out (popover="man&#1;ual" is now refused), plus an entry for the repeated-attribute fix. The root changelog extends the Read numeric references in attribute values as the browser does #610 id warning entry and adds the preload fix.

Tests

  • test_output_parsers.py: each changed Citry UI check refuses a tag whose first value is one it does not accept, and accepts the tag with the two values swapped. Each case runs twice: with the current core parser, and with the core parser's first-value step turned off, which behaves like Citry releases before 0.9.0. Control characters in tag names come out escaped.
  • test_attribute_numeric_references.py: LongReferenceSafeParser gives the first value with and without a reference in the tag; the id warning and the Vue mount check read only the first id.
  • test_long_character_references.py: the input is split at every position except inside the 5,000-digit runs of zeros (where it splits every 1,000th position), including right after & and &#.

I ran each new test against the code without its fix, and each one fails there.

Left out

These build and test tools read Citry's own output with dict(attrs) or dict(tag.attrs) and make no decision about user pages, so this PR leaves them as they are: scripts/vue_render_parity/check.py, scripts/generate_html_attribute_values.py, docs_site/_internal/base_path.py, docs_site/_internal/assemble.py.

Two Rust lookups in citry_html_transform also don't use the browser's first-value rule, and I left them for a separate change:

  • marker.rs reads the c-render-id of a <template> placeholder, which the server replaces with the child's HTML before the page is sent.
  • transformer.rs handles the track_added_attributes_for_tags_with_this_attribute option, which citry does not use.

🤖 Generated with Claude Code

… checks

A browser keeps the first of two attributes with the same name on one
tag. The citry_ui checks of rendered fills read `dict(attrs)`, which
keeps the last, so `<span tabindex="0" tabindex="-1">` passed the
Listbox option check while the browser makes the span focusable.

- `LongReferenceSafeParser` hands the start tag handlers of subclasses
  that read attributes each repeated name once, with its first value.
  The repeated `id` warning now counts only the first `id` of an
  element, and the Vue mount host check reads a repeated `id` the same
  way, so `<div id="app" ID="x">` is the host with one attribute.
- The citry_ui checks read their tags through their own
  `first_attribute_occurrences`, because Citry UI also runs on Citry
  releases whose parser keeps every occurrence.
- `LongReferenceSafeParser` holds back a lone `&` at the end of a chunk
  until the next chunk arrives, so a long decimal reference split right
  after the `&` no longer raises `ValueError`. That error made Citry
  skip its preload links for such a page.
- The citry_ui check messages write control characters in a tag name as
  escapes such as `\x1b`.

The citry_ui changelog also gets the entry for #610's stricter reading
of numeric references in attribute values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit e55f87c into main Nov 14, 2026
23 of 33 checks passed
@JuroOravec
JuroOravec deleted the fix/citry-ui-validator-attrs branch November 14, 2026 18:01
JuroOravec added a commit that referenced this pull request Nov 14, 2026
…ight merged changes (#682)

Add one record under docs/security/reviews/ for each of the eight published
0.8.0 advisories (GHSA-4hj5, -8xvf, -7qpw, -g658, -x6rm, -h524, -xmx5,
-xg8c) and for each of the pull requests that Mechanism 7, step 7 owes one:
#610, #640, #651, #652, #653, #658, #674 and #675. Each record says only what
the public pull request, the published advisory, the merged code and its tests
show, and lists what was not checked.

The reviews README describes how a record for a published advisory differs
from a pull request record. The Mechanism 7 list in CLAUDE.md gains the two
places that GHSA-7qpw added: parser rules browsers differ on, and the page's
declared encoding.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant