Skip to content

Commit

Permalink
Fix 22231
Browse files Browse the repository at this point in the history
  • Loading branch information
esquerbatua committed Sep 21, 2024
1 parent 81487c5 commit 3fc1c52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions vlib/v/parser/tmpl.v
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ 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
round1 := ['\\', '\\\\', r"'", "\\'", r'@', r'$']
round2 := [r'$$', r'\@']
mut rline := line.replace_each(round1).replace_each(round2)
replace_pairs := ['\\', '\\\\', r"'", "\\'", r'@', r'$', r'$$', r'\@']
mut rline := line.replace_each(replace_pairs)
comptime_call_str := rline.find_between('\${', '}')
if comptime_call_str.contains("\\'") {
rline = rline.replace(comptime_call_str, comptime_call_str.replace("\\'", r"'"))
Expand Down
2 changes: 2 additions & 0 deletions vlib/v/tests/tmpl/dot_var.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.@one
.${two}
9 changes: 9 additions & 0 deletions vlib/v/tests/tmpl_dot_var_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn template() string {
one := 1
two := 2
return $tmpl('tmpl/dot_var.txt')
}

fn test_tmpl_with_dot_var() {
assert template() == '.1\r\n.2\r\n'
}

0 comments on commit 3fc1c52

Please sign in to comment.