Consume the escaped Windows newline (\r\n) for FStringMiddle (#7722)

## Summary

This PR fixes a bug where if a Windows newline (`\r\n`) character was
escaped, then only the `\r` was consumed and not `\n` leading to an
unterminated string error.

## Test Plan

Add new test cases to check the newline escapes.

fixes: #7632
This commit is contained in:
Dhruv Manilawala 2023-10-01 07:58:20 +05:30 committed by GitHub
parent e72d617f4b
commit e91ffe3e93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 2 deletions

View file

@ -0,0 +1,25 @@
---
source: crates/ruff_python_parser/src/lexer.rs
expression: fstring_single_quote_escape_eol(MAC_EOL)
---
[
(
FStringStart,
0..2,
),
(
FStringMiddle {
value: "text \\\r more text",
is_raw: false,
},
2..19,
),
(
FStringEnd,
19..20,
),
(
Newline,
20..20,
),
]

View file

@ -0,0 +1,25 @@
---
source: crates/ruff_python_parser/src/lexer.rs
expression: fstring_single_quote_escape_eol(UNIX_EOL)
---
[
(
FStringStart,
0..2,
),
(
FStringMiddle {
value: "text \\\n more text",
is_raw: false,
},
2..19,
),
(
FStringEnd,
19..20,
),
(
Newline,
20..20,
),
]

View file

@ -0,0 +1,25 @@
---
source: crates/ruff_python_parser/src/lexer.rs
expression: fstring_single_quote_escape_eol(WINDOWS_EOL)
---
[
(
FStringStart,
0..2,
),
(
FStringMiddle {
value: "text \\\r\n more text",
is_raw: false,
},
2..20,
),
(
FStringEnd,
20..21,
),
(
Newline,
21..21,
),
]