mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
scanner: remove error check for embedded \x00 chars in c'literals'
This commit is contained in:
parent
10e0c39115
commit
2fb5c91f4d
@ -1113,6 +1113,7 @@ fn (mut s Scanner) ident_string() string {
|
|||||||
q := s.text[s.pos]
|
q := s.text[s.pos]
|
||||||
is_quote := q == single_quote || q == double_quote
|
is_quote := q == single_quote || q == double_quote
|
||||||
is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1] == `r`
|
is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1] == `r`
|
||||||
|
is_cstr := is_quote && s.pos > 0 && s.text[s.pos - 1] == `c`
|
||||||
if is_quote && !s.is_inside_string {
|
if is_quote && !s.is_inside_string {
|
||||||
s.quote = q
|
s.quote = q
|
||||||
}
|
}
|
||||||
@ -1145,13 +1146,15 @@ fn (mut s Scanner) ident_string() string {
|
|||||||
// Don't allow \0
|
// Don't allow \0
|
||||||
if c == `0` && s.pos > 2 && s.text[s.pos - 1] == slash {
|
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() {
|
||||||
} else {
|
} else if !is_cstr {
|
||||||
s.error('0 character in a string literal')
|
s.error('0 character in a string literal')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Don't allow \x00
|
// Don't allow \x00
|
||||||
if c == `0` && s.pos > 5 && s.expect('\\x0', s.pos - 3) {
|
if c == `0` && s.pos > 5 && s.expect('\\x0', s.pos - 3) {
|
||||||
s.error('0 character in a string literal')
|
if !is_cstr {
|
||||||
|
s.error('0 character in a string literal')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ${var} (ignore in vfmt mode)
|
// ${var} (ignore in vfmt mode)
|
||||||
if c == `{` && prevc == `$` && !is_raw && s.count_symbol_before(s.pos - 2, slash) % 2 == 0 {
|
if c == `{` && prevc == `$` && !is_raw && s.count_symbol_before(s.pos - 2, slash) % 2 == 0 {
|
||||||
|
@ -7,3 +7,10 @@ fn test_cstring() {
|
|||||||
assert hlen2 == 5
|
assert hlen2 == 5
|
||||||
assert wlen == 5
|
assert wlen == 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_cstring_with_zeros() {
|
||||||
|
rawbytes := c'\x00username\x00password'
|
||||||
|
s := string(rawbytes, 18)
|
||||||
|
h := s.bytes().hex()
|
||||||
|
assert h == '00757365726e616d650070617373776f7264'
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user