mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
tokenizer: fix crash on multiline string with only 1 backslash
Closes #8904
This commit is contained in:
parent
3ed6379192
commit
44de884980
@ -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| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user