diff --git a/vlib/v/parser/tmpl.v b/vlib/v/parser/tmpl.v index 4fa4ce00ac359b..650e07e5e3f6a2 100644 --- a/vlib/v/parser/tmpl.v +++ b/vlib/v/parser/tmpl.v @@ -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("\\'") { diff --git a/vlib/v/tests/tmpl/escape.txt b/vlib/v/tests/tmpl/escape.txt new file mode 100644 index 00000000000000..11fc11befd18b6 --- /dev/null +++ b/vlib/v/tests/tmpl/escape.txt @@ -0,0 +1,3 @@ +Hello @@world +Hello @world +Hello @ @world @ \ No newline at end of file diff --git a/vlib/v/tests/tmpl_escape_test.v b/vlib/v/tests/tmpl_escape_test.v new file mode 100644 index 00000000000000..7856d42205c12b --- /dev/null +++ b/vlib/v/tests/tmpl_escape_test.v @@ -0,0 +1,9 @@ +fn test_escape() { + world := 'world!' + res := $tmpl('tmpl/escape.txt') + + assert res == 'Hello @world +Hello world! +Hello $ world! $ +' +}