From 06631f3cfd511abbb91979f35c8736c595c8af15 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 15 Apr 2026 16:10:24 +0300 Subject: [PATCH] parser: fix wrong replacing of @ to $ in links in html vweb templates (fixes #11978) --- vlib/v/parser/tmpl.v | 14 ++++++++------ vlib/v/tests/at_in_url_template.html | 2 ++ vlib/v/tests/tmpl_escape_test.v | 4 +++- vlib/v/tests/tmpl_test.v | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/vlib/v/parser/tmpl.v b/vlib/v/parser/tmpl.v index 9fc115d49..5bbc964b6 100644 --- a/vlib/v/parser/tmpl.v +++ b/vlib/v/parser/tmpl.v @@ -288,13 +288,15 @@ fn insert_template_code(fn_name string, tmpl_str_start string, line string) stri i += 2 continue } - // Keep package-version URLs like `jquery@3.6.0` unchanged. - if i + 1 < rewritten_line.len && rewritten_line[i + 1].is_digit() { - sb.write_u8(`@`) - i++ - continue + if i + 1 < rewritten_line.len { + next := rewritten_line[i + 1] + if next == `{` || is_tmpl_ident_start(next) { + sb.write_u8(`$`) + i++ + continue + } } - sb.write_u8(`$`) + sb.write_u8(`@`) i++ continue } diff --git a/vlib/v/tests/at_in_url_template.html b/vlib/v/tests/at_in_url_template.html index 32614998f..63e727a26 100644 --- a/vlib/v/tests/at_in_url_template.html +++ b/vlib/v/tests/at_in_url_template.html @@ -1,2 +1,4 @@ + +
@title
diff --git a/vlib/v/tests/tmpl_escape_test.v b/vlib/v/tests/tmpl_escape_test.v index 390c14eac..a95a79697 100644 --- a/vlib/v/tests/tmpl_escape_test.v +++ b/vlib/v/tests/tmpl_escape_test.v @@ -4,7 +4,7 @@ fn test_escape() { assert res == 'Hello @world Hello world! -Hello $ world! $ +Hello @ world! @ ' } @@ -12,5 +12,7 @@ fn test_keeps_at_in_html_urls() { title := 'template ok' res := $tmpl('at_in_url_template.html') assert res.contains('https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js') + assert res.contains('https://unpkg.com/htmx.org@1.5.0') + assert res.contains('https://unpkg.com/hyperscript.org@0.8.1') assert res.contains('
template ok
') } diff --git a/vlib/v/tests/tmpl_test.v b/vlib/v/tests/tmpl_test.v index 39a3e3600..6852bd395 100644 --- a/vlib/v/tests/tmpl_test.v +++ b/vlib/v/tests/tmpl_test.v @@ -127,7 +127,7 @@ fn test_tmpl_comptime() { index := $tmpl('tmpl/index.html').trim_space() // dump(index) assert index.contains('
Line ending with percent %\n') - assert index.contains('
Line ending with at $\n') + assert index.contains('
Line ending with at @\n') assert index.contains('
Line ending with ampersand &\n') assert index.contains('
Line ending with hash #\n') assert index.contains('
Line ending with slash /\n') -- 2.39.5