File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -1113,6 +1113,7 @@ fn (mut s Scanner) ident_string() string {
11131113 q := s.text[s.pos]
11141114 is_quote := q == single_quote || q == double_quote
11151115 is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1 ] == `r`
1116+ is_cstr := is_quote && s.pos > 0 && s.text[s.pos - 1 ] == `c`
11161117 if is_quote && ! s.is_inside_string {
11171118 s.quote = q
11181119 }
@@ -1145,13 +1146,15 @@ fn (mut s Scanner) ident_string() string {
11451146 // Don't allow \0
11461147 if c == `0` && s.pos > 2 && s.text[s.pos - 1 ] == slash {
11471148 if s.pos < s.text.len - 1 && s.text[s.pos + 1 ].is_digit () {
1148- } else {
1149+ } else if ! is_cstr {
11491150 s.error ('0 character in a string literal' )
11501151 }
11511152 }
11521153 // Don't allow \x00
11531154 if c == `0` && s.pos > 5 && s.expect ('\\ x0' , s.pos - 3 ) {
1154- s.error ('0 character in a string literal' )
1155+ if ! is_cstr {
1156+ s.error ('0 character in a string literal' )
1157+ }
11551158 }
11561159 // ${var} (ignore in vfmt mode)
11571160 if c == `{` && prevc == `$` && ! is_raw && s.count_symbol_before (s.pos - 2 , slash) % 2 == 0 {
Original file line number Diff line number Diff line change @@ -7,3 +7,10 @@ fn test_cstring() {
77 assert hlen2 == 5
88 assert wlen == 5
99}
10+
11+ fn test_cstring_with_zeros () {
12+ rawbytes := c '\x00 username\x00 password'
13+ s := string (rawbytes, 18 )
14+ h := s.bytes ().hex ()
15+ assert h == '00757365726e616d650070617373776f7264'
16+ }
You can’t perform that action at this time.
0 commit comments