Fix parsing crash with dollar escapes

This commit is contained in:
Joshua Warner 2024-12-02 17:39:01 -08:00
parent 89a64fed74
commit e47d7924d3
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
4 changed files with 8 additions and 0 deletions

View file

@ -181,6 +181,7 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
match one_byte {
b'"' if !is_single_quote => {
preceded_by_dollar = false;
if segment_parsed_bytes == 1 && segments.is_empty() {
// special case of the empty string
if is_multiline {
@ -252,6 +253,7 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
};
}
b'\'' if is_single_quote => {
preceded_by_dollar = false;
end_segment!(StrSegment::Plaintext);
let expr = if segments.len() == 1 {
@ -318,6 +320,7 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
));
}
b'\n' => {
preceded_by_dollar = false;
if is_multiline {
let without_newline = &state.bytes()[0..(segment_parsed_bytes - 1)];
let with_newline = &state.bytes()[0..segment_parsed_bytes];
@ -352,6 +355,7 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
}
}
b'\\' => {
preceded_by_dollar = false;
// We're about to begin an escaped segment of some sort!
//
// Record the current segment so we can begin a new one.