Skip to content

Commit

Permalink
cgen: fix escape of non-ascii characters in string interpolation (fix v…
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 authored Jan 9, 2024
1 parent 89f06d3 commit 14f3c95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/str_intp.v
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
g.write(' str_intp(${node.vals.len}, ')
g.write('_MOV((StrIntpData[]){')
for i, val in node.vals {
mut escaped_val := util.smart_quote(val, false)
mut escaped_val := cescape_nonascii(util.smart_quote(val, false))
escaped_val = escaped_val.replace('\0', '\\0')

if escaped_val.len > 0 {
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/string_interpolation_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,10 @@ fn test_contains_zero_characters() {
assert str.len == 7
assert str == 'abc\0abc'
}

// for issue: 20432
// non-ascii escape was lost
fn test_interpo_non_ascii_characters() {
hello := '你好'
assert '${hello},世界!' == '你好,世界!'
}

0 comments on commit 14f3c95

Please sign in to comment.