Skip to content

Commit 2b176bc

Browse files
miss-islingtonmgmacias95pablogsal
authored
[3.12] gh-105017: Fix including additional NL token when using CRLF (GH-105022) (#105023)
Co-authored-by: Marta Gómez Macías <[email protected]> Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent edd0cb8 commit 2b176bc

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Lib/test/test_tokenize.py

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ def test_basic(self):
8484
NEWLINE '\\n' (4, 26) (4, 27)
8585
DEDENT '' (5, 0) (5, 0)
8686
""")
87+
88+
self.check_tokenize("foo='bar'\r\n", """\
89+
NAME 'foo' (1, 0) (1, 3)
90+
OP '=' (1, 3) (1, 4)
91+
STRING "'bar'" (1, 4) (1, 9)
92+
NEWLINE '\\n' (1, 9) (1, 10)
93+
""")
94+
8795
indent_error_file = b"""\
8896
def k(x):
8997
x += 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not include an additional final ``NL`` token when parsing files having CRLF lines. Patch by Marta Gómez.

Parser/tokenizer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
800800
}
801801
/* If this is exec input, add a newline to the end of the string if
802802
there isn't one already. */
803-
if (exec_input && c != '\n') {
803+
if (exec_input && c != '\n' && c != '\0') {
804804
*current = '\n';
805805
current++;
806806
}

0 commit comments

Comments
 (0)