tokenizer: fix crash on multiline string with only 1 backslash

Closes #8904
This commit is contained in:
Andrew Kelley 2021-05-25 18:13:10 -07:00
parent 3ed6379192
commit 44de884980

View File

@ -698,7 +698,10 @@ pub const Tokenizer = struct {
'\\' => {
state = .multiline_string_literal_line;
},
else => break,
else => {
result.tag = .invalid;
break;
},
},
.string_literal => switch (c) {
'\\' => {
@ -1960,7 +1963,7 @@ test "tokenizer - number literals octal" {
try testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
}
test "tokenizer - number literals hexadeciaml" {
test "tokenizer - number literals hexadecimal" {
try testTokenize("0x0", &.{.integer_literal});
try testTokenize("0x1", &.{.integer_literal});
try testTokenize("0x2", &.{.integer_literal});
@ -2046,6 +2049,10 @@ test "tokenizer - number literals hexadeciaml" {
try testTokenize("0x0.0p0_", &.{ .invalid, .eof });
}
test "tokenizer - multi line string literal with only 1 backslash" {
try testTokenize("x \\\n;", &.{ .identifier, .invalid, .semicolon });
}
fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void {
var tokenizer = Tokenizer.init(source);
for (expected_tokens) |expected_token_id| {