mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-105017: Fix including additional NL token when using CRLF (GH-105022) (#105023)
Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
edd0cb8e77
commit
2b176bc902
3 changed files with 10 additions and 1 deletions
|
@ -84,6 +84,14 @@ class TokenizeTest(TestCase):
|
||||||
NEWLINE '\\n' (4, 26) (4, 27)
|
NEWLINE '\\n' (4, 26) (4, 27)
|
||||||
DEDENT '' (5, 0) (5, 0)
|
DEDENT '' (5, 0) (5, 0)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
self.check_tokenize("foo='bar'\r\n", """\
|
||||||
|
NAME 'foo' (1, 0) (1, 3)
|
||||||
|
OP '=' (1, 3) (1, 4)
|
||||||
|
STRING "'bar'" (1, 4) (1, 9)
|
||||||
|
NEWLINE '\\n' (1, 9) (1, 10)
|
||||||
|
""")
|
||||||
|
|
||||||
indent_error_file = b"""\
|
indent_error_file = b"""\
|
||||||
def k(x):
|
def k(x):
|
||||||
x += 2
|
x += 2
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Do not include an additional final ``NL`` token when parsing files having CRLF lines. Patch by Marta Gómez.
|
|
@ -800,7 +800,7 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
|
||||||
}
|
}
|
||||||
/* If this is exec input, add a newline to the end of the string if
|
/* If this is exec input, add a newline to the end of the string if
|
||||||
there isn't one already. */
|
there isn't one already. */
|
||||||
if (exec_input && c != '\n') {
|
if (exec_input && c != '\n' && c != '\0') {
|
||||||
*current = '\n';
|
*current = '\n';
|
||||||
current++;
|
current++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue