From 6071e06e102acb22531b1dca7608a821f7894f66 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 24 Sep 2024 19:01:14 -0300 Subject: [PATCH 1/2] fix --- vlib/v/parser/tmpl.v | 2 +- vlib/v/tests/tmpl_escape_test.v | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/tmpl_escape_test.v 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_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! $ +' +} From b9c1f590e466597a082a30ad447b4bf3aa90df05 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 24 Sep 2024 19:01:24 -0300 Subject: [PATCH 2/2] fix --- vlib/v/tests/tmpl/escape.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 vlib/v/tests/tmpl/escape.txt 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