Skip to content

fix: decode attribute values in Vue components by the attribute rule, as Vue does - #314

Merged
JuroOravec merged 2 commits into
mainfrom
fix/vue-attribute-entities
Oct 24, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/vue-attribute-entities

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Fixes #311

What was wrong

In a component that uses Vue, a link such as

<a href="/search?q=x&region=eu">go</a>

reached the browser as href="/search?q=x®ion=eu", so the link broke.
A static Citry page and Vue's own compiler keep &region=eu.

HTML reads a legacy name (a named reference that HTML also accepts without
;, such as &reg, &copy or &amp) by two rules. In text it always
decodes, so &copyX reads as ©X. In an attribute value it stays as
written when = or a letter or digit follows it, which keeps query
strings intact. The patched Vize emitter in
third_party/rust/vize_s1_to_s2 decoded attribute values and directive
expressions with the text rule. @vue/compiler-dom 3.5.44 uses the
attribute rule for both, so :title="'a&copy=b'" keeps &copy=b in Vue.

While sweeping the emitter I found a second case of the same kind: it
decoded references in names too. HTML never does that, so Vue names the
slot in <template #a&copy> a&copy, while Citry named it a©. The same
happened to directive modifiers (v-foo.m&copy) and to slot prop names.

The fix

  • src/emit/entity.rs and src/emit/js.rs gain
    decode_html_attribute_entities and escape_js_attribute_string, which
    decode with the attribute rule (Context::Attribute), and
    escape_js_name, which escapes a name without decoding it. Text keeps
    the text rule.
  • The emitters for static attributes, bound values (:name and
    v-bind, through prefix.rs), class, style, key (on elements,
    v-for rows and <template> wrappers), v-html, slot names, slot props
    and component props now use the attribute rule.
  • The emitters that decoded a name now use escape_js_name: #name
    slot names, slot prop names, the attribute names that a <template>
    wrapper or a static prop writes, directive names and directive
    modifiers.
  • Citry's check for whether an authored attribute reads its component
    instance (_source_attribute_reads_instance in
    citry/_vue/direct_capture.py) and its root markers now decode with
    decode_attribute_entities, so they read the value the way the compiler
    does.
  • The patched crates and the compiler identity move from
    0.420.0+citry.3 to 0.420.0+citry.4. citry checks that the compiler
    reports exactly this identity, so it cannot run with a citry-core
    build that still decodes by the text rule. Both crates move together
    because they share one version. Each README.citry.md lists the change.

I compared the emitter with @vue/compiler-dom 3.5.44 on static, bound,
class, style, key, v-html, dynamic argument, SVG, slot, component,
name, &amp; and numeric cases. Static attribute values, bound values,
v-html, class, style, keys and names now decode as Vue decodes them.
The other differences in those cases also exist on main and do not
involve references. For example, Citry writes a static style as the
authored string where Vue writes an object, adds a PROPS patch flag to
innerHTML, and marks a v-for with a static key as an unkeyed
fragment.

Not fixed here

A string literal inside v-on, v-if, v-show, v-for, v-slot,
v-model, v-text, v-memo or a custom directive's value still keeps
its references as written, where Vue decodes them:
@click="msg = 'Tom &amp; Jerry'" sets msg to Tom &amp; Jerry, while
Vue sets Tom & Jerry. This already happens on main. The emitter reads
those expressions as raw text, and changing that touches every directive
kind and the event-handler statement rule (the raw &amp; holds a ;, so
the handler above is also written as a statement block), so the fix
belongs in its own change, tracked in #313.

Tests

  • citry: a hydrated page with href="/search?q=x&region=eu&copy",
    :title="'a&copy=b'" and the text t &copy keeps the attribute values
    as written, decodes the final &copy and the text, and hydrates with no
    declines. Seven compiler cases check class, a v-for key, a component
    prop, v-html, a slot name, a slot prop name and a #name slot against
    the code Vue writes. A direct test covers the direct_capture.py
    change. These run in the repository gate, and each fails on main.
  • vize_s1_to_s2: a new citry_attribute_entities target checks twelve
    templates against the code Vue writes for them, and a unit test in
    entity.rs checks both rules. The new target fails on main. The
    repository gate does not run third_party crates' tests, which is why
    the Python tests repeat the main cases.

The emit_if and metamorphic targets, and the upstream targets that
need insta or vize_atelier_dom, also fail or do not build on main;
this change does not touch them.

Changelog: a Fixes line in CHANGELOG.md.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 24, 2026 14:29
In a component that uses Vue, the patched Vize emitter decoded attribute
values with the text rule. A legacy name (a named reference HTML also
accepts without `;`) before `=` or a letter or digit was decoded, so
`href="/search?q=x&region=eu"` compiled to `"/search?q=x®ion=eu"`. The
browser and Vue 3.5.44 keep such a name as written in an attribute value.

The emitter now decodes static attribute values, bound values, `v-html`,
`class`, `style`, keys and slot props with the attribute rule, and keeps
the text rule for text. Names (slot, slot prop and directive names,
directive modifiers, and the attribute names a `<template>` wrapper or a
static prop writes) are not decoded at all, because HTML never decodes a
reference in a name: `<template #a&copy>` names the slot `a&copy`, as in
Vue. Citry's Python checks of source attribute values and root markers
(in `direct_capture.py`) decode with decode_attribute_entities for the
same reason.

The patched Vize crates and the compiler identity move to
0.420.0+citry.4, because the compiled output changed, and citry checks
the identity to make sure it runs with a citry-core that has this fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 1a1a9ec into main Oct 24, 2026
7 checks passed
@JuroOravec
JuroOravec deleted the fix/vue-attribute-entities branch October 24, 2026 12:58
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.

In Vue components, an attribute value like ?a=1&region=eu loses its text: legacy references are decoded with the text rule

1 participant