From 1c886ad0671bfa72ae0542997522b7edb11f963a Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Sat, 19 Sep 2020 21:39:18 +0530 Subject: [PATCH] scanner: add check for `!is_raw` for null `\0` (#6427) --- vlib/builtin/string_test.v | 4 ++++ vlib/v/scanner/scanner.v | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 20c8d6b8eb..d52969abab 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -725,6 +725,10 @@ fn test_raw() { println(lines) assert lines.len == 1 println('raw string: "$raw"') + + raw2 := r'Hello V\0' + assert raw2[7] == `\\` + assert raw2[8] == `0` } fn test_raw_with_quotes() { diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 02ba60d33c..db63722d91 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -1217,14 +1217,14 @@ fn (mut s Scanner) ident_string() string { // Don't allow \0 if c == `0` && s.pos > 2 && s.text[s.pos - 1] == slash { if (s.pos < s.text.len - 1 && s.text[s.pos + 1].is_digit()) || s.count_symbol_before(s.pos - 1, slash) % 2 == 0 { - } else if !is_cstr { + } else if !is_cstr && !is_raw { s.error('0 character in a string literal') } } // Don't allow \x00 if c == `0` && s.pos > 5 && s.expect('\\x0', s.pos - 3) { if s.count_symbol_before(s.pos - 3, slash) % 2 == 0 { - } else if !is_cstr { + } else if !is_cstr && !is_raw { s.error('0 character in a string literal') } }