scanner: remove error check for embedded \x00 chars in c'literals'
parent
10e0c39115
commit
2fb5c91f4d
|
@ -1113,6 +1113,7 @@ fn (mut s Scanner) ident_string() string {
|
|||
q := s.text[s.pos]
|
||||
is_quote := q == single_quote || q == double_quote
|
||||
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 {
|
||||
s.quote = q
|
||||
}
|
||||
|
@ -1145,14 +1146,16 @@ 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() {
|
||||
} else {
|
||||
} 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 {
|
||||
s.error('0 character in a string literal')
|
||||
}
|
||||
}
|
||||
// ${var} (ignore in vfmt mode)
|
||||
if c == `{` && prevc == `$` && !is_raw && s.count_symbol_before(s.pos - 2, slash) % 2 == 0 {
|
||||
s.is_inside_string = true
|
||||
|
|
|
@ -7,3 +7,10 @@ fn test_cstring() {
|
|||
assert hlen2 == 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