1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

scanner: add check for !is_raw for null \0 (#6427)

This commit is contained in:
Swastik Baranwal 2020-09-19 21:39:18 +05:30 committed by GitHub
parent 4b0e7fc979
commit 1c886ad067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -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() {

View File

@ -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')
}
}