Repository navigation
parser: fix @@ escape before complex at-expressions in templates - #27701
Merged
Merged
Conversation
In compile-time templates ($tmpl / $veb.html()), the documented `@@` escape for a literal `@` was broken whenever it directly preceded a complex at-expression: `@@get('/x')` rendered as `@{get('/x')}` instead of the literal `@get('/x')`. This affected any `@@` followed by `ident(...)`, `ident[...]` or `ident.field`. Root cause: in rewrite_complex_template_at_expressions (vlib/v/parser/tmpl.v), the `@@` branch wrote a single `@` and advanced the index by only 1. The second `@` was then re-parsed as the start of a complex at-expression and wrapped in `@{...}`. The bare-ident case (`@@world`) already worked because find_tmpl_complex_at_expr_end returns -1 for a bare identifier, which is why the existing escape test did not catch this. Fix: write both `@` characters and advance the index by 2, deferring the final `@@` -> `@` collapse to insert_template_code (which already handles it). Added a regression test covering `@@get('/x')` and `@@post('/save')`. Related to vlang#22299 (bare-ident `@@` case, fixed).
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Member
|
Thanks! |
rilaaax
pushed a commit
to rilaaax/v
that referenced
this pull request
Jul 9, 2026
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.
What & why
Fixes #27700.
In compile-time templates (
$tmpl/$veb.html()), the documented@@escapefor a literal
@rendered incorrectly whenever it preceded a complexat-expression (
ident(...),ident[...],ident.field):@@get('/x')rendered as@{get('/x')}instead of the literal@get('/x').This is a real-world pain point for Datastar hypermedia apps written with
veb, where HTML attributes carry action verbs(
data-on:click="@get('/increment')") that must be escaped as@@get(...)` ina V template.
Root cause
In
rewrite_complex_template_at_expressions(vlib/v/parser/tmpl.v), the@@branch wrote a single@and advanced the index by only 1, leaving thesecond
@to be re-parsed as the start of a complex at-expression (wrappedinto
@{...}). The bare-ident case (@@world) already worked becausefind_tmpl_complex_at_expr_endreturns-1for a bare identifier, so theexisting escape test never exercised the complex-suffix case.
The fix
Write both
@characters and advance the index by 2, deferring the@@→@collapse toinsert_template_code(which already handles it).Tests
test_escape_double_at_before_complex_at_expressioncovering@@get('/x')and@@post('/save').@@world/@{expr}/@urlbehaviors are unchanged.v test vlib/v/tests/→ 2175 passed, 6 skipped, 0 failures (full templatesuite green, including the new regression). GitHub CI runs the complete
suite on this PR.