Skip to content

Commit

Permalink
parser: add back the escape for @ using @@ in $tmpl() templates, …
Browse files Browse the repository at this point in the history
…add tests (the regression happened in 3115796 from 2024-09-22) (#22303)
  • Loading branch information
felipensp committed Sep 25, 2024
1 parent e1900ae commit 1a4ad55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/parser/tmpl.v
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn insert_template_code(fn_name string, tmpl_str_start string, line string) stri
// HTML, may include `@var`
// escaped by cgen, unless it's a `vweb.RawHtml` string
trailing_bs := tmpl_str_end + 'sb_${fn_name}.write_u8(92)\n' + tmpl_str_start
replace_pairs := ['\\', '\\\\', r"'", "\\'", r'@', r'$', r'$$', r'\@']
replace_pairs := ['\\', '\\\\', r"'", "\\'", r'@@', r'@', r'@', r'$', r'$$', r'\@']
mut rline := line.replace_each(replace_pairs)
comptime_call_str := rline.find_between('\${', '}')
if comptime_call_str.contains("\\'") {
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/tests/tmpl/escape.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello @@world
Hello @world
Hello @ @world @
9 changes: 9 additions & 0 deletions vlib/v/tests/tmpl_escape_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn test_escape() {
world := 'world!'
res := $tmpl('tmpl/escape.txt')

assert res == 'Hello @world
Hello world!
Hello $ world! $
'
}

0 comments on commit 1a4ad55

Please sign in to comment.