Repository navigation
fix: accept character references the browser reads as text in <c-raw> blocks and Markup - #310
Merged
Merged
Conversation
… and Markup In an interactive component, Citry checks that a <c-raw> block or Markup value is complete HTML (validate_html_fragment_boundary), because Vue inserts it as one block. The check refused every tokenizer error, so `© 2026` (a legacy name without `;`), ` `, ``, `€` or `` failed with a message about tag rules the HTML does not break. - The check now lets every character reference error pass (is_character_reference_error: missing semicolon, unknown name, control, noncharacter, null, surrogate and out-of-range references, and `&#` with no digits). Each reference becomes text, so it cannot open or close an element; html5gum decodes the text cases as parse5 7.3.0 does, which a Rust test checks. The full page parse that guards hydration stays strict: the server escapes `&` in what it writes, and <c-raw> and Markup blocks are cut out of that parse after their own checks. - For any other tokenizer error, the check now names it. The Python message says the HTML is not well-formed, names the error, links to the HTML standard's list of parse errors and, for a stray `<`, says to write it as `<`; the tag-rule message keeps the shape problems. - The raw, expressions and 0.6.0 upgrade docs mention the new message. Fixes #298 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #298
What was wrong
In a component with browser behavior (
js), Citry checks that each<c-raw>block and eachMarkupvalue is complete HTML, because Vueinserts it as one block (
validate_html_fragment_boundaryincrates/citry_html_transform/src/output_scanner.rs). The check refusedevery tokenizer error, including the ones the HTML standard reports for a
character reference it still decodes. So a footer with
© 2026failed:
The message described tag rules the HTML does not break.
The fix
Of the issue's two options I took the first, with the browser as the
reference: a character reference the browser reads as text is accepted,
and any other tokenizer error gets a message that names it.
is_character_reference_error): a legacy name without;(© 2026, ), an unknown name (&foo;, kept aswritten), and numeric references to a control character (
, and€toŸ, most of which map to Windows-1252), anoncharacter (
), NUL, a surrogate or a value past U+10FFFF(the last three read as U+FFFD), plus
&#with no digits (kept aswritten). These are exactly the HTML standard's character-reference
errors. Each one becomes text, so it cannot open or close an element. A
Rust test checks, for each text case, that html5gum decodes it exactly
as parse5 7.3.0 (the parser jsdom uses) does; I checked parse5
separately.
opaque HTML has the HTML parse error <name>, and the Python message says the block "isnot well-formed HTML", names the error and links to the HTML standard's
list of parse errors. A stray
<(invalid-first-character-of-tag-nameand its two relatives) also gets "A '<' that does not start a tag must
be written as '<'", which the tag-rule message used to carry. Shape
problems (an unclosed tag, a self-closed
<iframe/>) keep the tag-rulemessage, now without the
<clause it can no longer reach.The full page parse that guards hydration
(
parse_div_fragment_with_lexical_text, the same tokenizer callback)stays strict about character references: the server escapes
&ineverything it writes, and
<c-raw>blocks andMarkupvalues arechecked by this fragment check and by
static_html_in_context, then cutout of the page parse. The reviewer confirmed such blocks hydrate, with
the default check and with the full parse forced.
validate_html_fragment_boundarynow returnsResult<(), String>instead of
Result<(), &'static str>so the message can carry theerror's name; its only callers are the PyO3 wrapper (unchanged) and
Citry's Python code. Its doc comment records the decision. The raw,
expressions and 0.6.0 upgrade docs now mention the "is not well-formed
HTML" message for a stray
<.Tests
citry_html_transform): the issue's table plus surrogate andout-of-range references, each accepted with the decoded text checked,
and the named-error and shape-error messages.
citry_core: the Python API accepts the references and nameseof-in-comment.citry: the issue's footer, with© 2026,and€,renders, writes the block as is and hydrates; a
<p a="1"b="2">blockand a stray
<each fail with the named-error message.Changelog: a Fixes line in
CHANGELOG.mdand a Fixed line inpackages/py/citry_core/CHANGELOG.md.Found during review, not fixed here
decoded with the text rule:
<a href="/search?q=x®ion=eu">compiles to
href: "/search?q=x®ion=eu", so the URL breaks, whileVue's own compiler and a static Citry page keep
®ion=eu.Markup("ab")in an interactive component showsab, because Python'shtml.unescapedrops,and, while the browser and static pages keep the code point.Both are separate code paths and need their own issues.
🤖 Generated with Claude Code