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

scanner: allow escape on null character (#6404)

This commit is contained in:
Henrixounez 2020-09-18 01:02:06 +02:00 committed by GitHub
parent a1e127ae46
commit 99574e465d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/string_char_null_err.vv:2:31: error: 0 character in a string literal
1 | fn main() {
2 | println('Null character: \0')
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println('Null character: \0')
}

View File

@ -1216,14 +1216,15 @@ 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() {
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 {
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 !is_cstr {
if s.count_symbol_before(s.pos - 3, slash) % 2 == 0 {
} else if !is_cstr {
s.error('0 character in a string literal')
}
}