Skip to content

Commit 1c545c3

Browse files
committed
Fix panic in lexing of unterminated asm text literal at EOF
1 parent a3c4639 commit 1c545c3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Lexing of conditional directive expressions containing compiler directives, comments, or strings.
1313
- Lexing of compiler directives similar to conditional directives (e.g. `{$if_}`).
14+
- Lexing of unterminated asm text literals at EOF.
1415

1516
## [0.3.0] - 2024-05-29
1617

core/src/defaults/lexer.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,16 +860,20 @@ fn asm_text_literal(mut args: LexArgs) -> OffsetAndTokenType {
860860
match args.next_byte() {
861861
Some(b'\\') => {
862862
args.offset += 1;
863+
if args.next_byte().is_some() {
864+
args.offset += 1;
865+
}
863866
}
864867
Some(b'\"') => {
865868
return (args.offset + 1, TT::TextLiteral(TLK::Asm));
866869
}
867870
None | Some(b'\n' | b'\r') => {
868871
break;
869872
}
870-
_ => {}
873+
_ => {
874+
args.offset += 1;
875+
}
871876
}
872-
args.offset += 1;
873877
}
874878

875879
warn_unterminated("asm text literal", args.input, start_offset);
@@ -2398,6 +2402,17 @@ mod tests {
23982402
);
23992403
}
24002404

2405+
#[test]
2406+
fn unterminated_asm_text_literal_at_eof() {
2407+
run_test(
2408+
r#"asm"\"#,
2409+
&[
2410+
("asm", TT::Keyword(KK::Asm)),
2411+
("\"\\", TT::TextLiteral(TLK::Unterminated)),
2412+
],
2413+
);
2414+
}
2415+
24012416
#[test]
24022417
fn inline_assembly_with_comments() {
24032418
run_test(

0 commit comments

Comments
 (0)