Repository navigation
fix: decode attribute values in Vue components by the attribute rule, as Vue does - #314
Merged
Merged
Conversation
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®ion=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©>` names the slot `a©`, 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]>
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 #311
What was wrong
In a component that uses Vue, a link such as
reached the browser as
href="/search?q=x®ion=eu", so the link broke.A static Citry page and Vue's own compiler keep
®ion=eu.HTML reads a legacy name (a named reference that HTML also accepts without
;, such as®,©or&) by two rules. In text it alwaysdecodes, so
©Xreads as©X. In an attribute value it stays aswritten when
=or a letter or digit follows it, which keeps querystrings intact. The patched Vize emitter in
third_party/rust/vize_s1_to_s2decoded attribute values and directiveexpressions with the text rule.
@vue/compiler-dom3.5.44 uses theattribute rule for both, so
:title="'a©=b'"keeps©=bin 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©>a©, while Citry named ita©. The samehappened to directive modifiers (
v-foo.m©) and to slot prop names.The fix
src/emit/entity.rsandsrc/emit/js.rsgaindecode_html_attribute_entitiesandescape_js_attribute_string, whichdecode with the attribute rule (
Context::Attribute), andescape_js_name, which escapes a name without decoding it. Text keepsthe text rule.
:nameandv-bind, throughprefix.rs),class,style,key(on elements,v-forrows and<template>wrappers),v-html, slot names, slot propsand component props now use the attribute rule.
escape_js_name:#nameslot names, slot prop names, the attribute names that a
<template>wrapper or a static prop writes, directive names and directive
modifiers.
instance (
_source_attribute_reads_instanceincitry/_vue/direct_capture.py) and its root markers now decode withdecode_attribute_entities, so they read the value the way the compilerdoes.
0.420.0+citry.3to0.420.0+citry.4.citrychecks that the compilerreports exactly this identity, so it cannot run with a
citry-corebuild that still decodes by the text rule. Both crates move together
because they share one version. Each
README.citry.mdlists the change.I compared the emitter with
@vue/compiler-dom3.5.44 on static, bound,class,style,key,v-html, dynamic argument, SVG, slot, component,name,
&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
mainand do notinvolve references. For example, Citry writes a static
styleas theauthored string where Vue writes an object, adds a
PROPSpatch flag toinnerHTML, and marks av-forwith a statickeyas an unkeyedfragment.
Not fixed here
A string literal inside
v-on,v-if,v-show,v-for,v-slot,v-model,v-text,v-memoor a custom directive's value still keepsits references as written, where Vue decodes them:
@click="msg = 'Tom & Jerry'"setsmsgtoTom & Jerry, whileVue sets
Tom & Jerry. This already happens onmain. The emitter readsthose expressions as raw text, and changing that touches every directive
kind and the event-handler statement rule (the raw
&holds a;, sothe 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 withhref="/search?q=x®ion=eu©",:title="'a©=b'"and the textt ©keeps the attribute valuesas written, decodes the final
©and the text, and hydrates with nodeclines. Seven compiler cases check
class, av-forkey, a componentprop,
v-html, a slot name, a slot prop name and a#nameslot againstthe code Vue writes. A direct test covers the
direct_capture.pychange. These run in the repository gate, and each fails on
main.vize_s1_to_s2: a newcitry_attribute_entitiestarget checks twelvetemplates against the code Vue writes for them, and a unit test in
entity.rschecks both rules. The new target fails onmain. Therepository gate does not run
third_partycrates' tests, which is whythe Python tests repeat the main cases.
The
emit_ifandmetamorphictargets, and the upstream targets thatneed
instaorvize_atelier_dom, also fail or do not build onmain;this change does not touch them.
Changelog: a Fixes line in
CHANGELOG.md.🤖 Generated with Claude Code