Skip to content

Commit 8fd20a5

Browse files
wooster0andrewrk
authored andcommitted
fix: disallow newline in char literal
1 parent 40447b2 commit 8fd20a5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/std/zig/tokenizer.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,10 @@ pub const Tokenizer = struct {
797797
remaining_code_units = 3;
798798
state = .char_literal_unicode;
799799
},
800+
'\n' => {
801+
result.tag = .invalid;
802+
break;
803+
},
800804
else => {
801805
state = .char_literal_end;
802806
},
@@ -1507,6 +1511,20 @@ test "tokenizer - code point literal with hex escape" {
15071511
, &.{ .invalid, .invalid });
15081512
}
15091513

1514+
test "tokenizer - newline in char literal" {
1515+
try testTokenize(
1516+
\\'
1517+
\\'
1518+
, &.{ .invalid, .invalid });
1519+
}
1520+
1521+
test "tokenizer - newline in string literal" {
1522+
try testTokenize(
1523+
\\"
1524+
\\"
1525+
, &.{ .invalid, .string_literal });
1526+
}
1527+
15101528
test "tokenizer - code point literal with unicode escapes" {
15111529
// Valid unicode escapes
15121530
try testTokenize(

0 commit comments

Comments
 (0)