Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmpl: add escape for @ using @@ #22303

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'\@']
spytheman marked this conversation as resolved.
Show resolved Hide resolved
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! $
'
}
Loading