tokenizer: detect null as non-first byte of a line comment
Line comments do not produce actual tokens so they need special handling for null bytes. Closes #14346
This commit is contained in:
@@ -1151,7 +1151,13 @@ pub const Tokenizer = struct {
|
||||
},
|
||||
},
|
||||
.line_comment => switch (c) {
|
||||
0 => break,
|
||||
0 => {
|
||||
if (self.index != self.buffer.len) {
|
||||
result.tag = .invalid;
|
||||
self.index += 1;
|
||||
}
|
||||
break;
|
||||
},
|
||||
'\n' => {
|
||||
state = .start;
|
||||
result.loc.start = self.index + 1;
|
||||
@@ -1865,6 +1871,9 @@ test "null byte before eof" {
|
||||
try testTokenize("//\x00", &.{.invalid});
|
||||
try testTokenize("\\\\\x00", &.{ .multiline_string_literal_line, .invalid });
|
||||
try testTokenize("\x00", &.{.invalid});
|
||||
try testTokenize("// NUL\x00\n", &.{.invalid});
|
||||
try testTokenize("///\x00\n", &.{ .doc_comment, .invalid });
|
||||
try testTokenize("/// NUL\x00\n", &.{ .doc_comment, .invalid });
|
||||
}
|
||||
|
||||
fn testTokenize(source: [:0]const u8, expected_token_tags: []const Token.Tag) !void {
|
||||
|
||||
Reference in New Issue
Block a user