Skip to content

Commit

Permalink
checker: fix missing check for escape char on unicode checker (#22462)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Oct 9, 2024
1 parent 98f66d8 commit 875faaf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vlib/v/checker/str.v
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ fn (mut c Checker) string_lit(mut node ast.StringLiteral) ast.Type {
start_idx := idx
idx++
next_ch := node.val[idx] or { return ast.string_type }
if next_ch == `u` {
if next_ch == `\\` {
// ignore escaping char
idx++
} else if next_ch == `u` {
idx++
mut ch := node.val[idx] or { return ast.string_type }
mut hex_char_count := 0
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/unicode_escape_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn test_main() {
a := r'\u306aefgh\t'

mut expected := '\\u306a'
expected += 'efgh\\t'

assert a == expected
assert a == '\\u306aefgh\\t'
}

0 comments on commit 875faaf

Please sign in to comment.