pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/45d648597b1146431bf3d91041e60d7f040e70bf

69241e157469407.css" /> gh-112387: Fix error positions for decoded strings with backwards tok… · python/cpython@45d6485 · GitHub
Skip to content

Commit 45d6485

Browse files
authored
gh-112387: Fix error positions for decoded strings with backwards tokenize errors (#112409)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent 2c8b191 commit 45d6485

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,10 @@ def test_error_parenthesis(self):
23342334
"""
23352335
self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['")
23362336

2337+
# Examples with dencodings
2338+
s = b'# coding=latin\n(aaaaaaaaaaaaaaaaa\naaaaaaaaaaa\xb5'
2339+
self._check_error(s, "'\(' was never closed")
2340+
23372341
def test_error_string_literal(self):
23382342

23392343
self._check_error("'blech", r"unterminated string literal \(.*\)$")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix error positions for decoded strings with backwards tokenize errors.
2+
Patch by Pablo Galindo

Parser/pegen_errors.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
282282
Py_ssize_t relative_lineno = p->starting_lineno ? lineno - p->starting_lineno + 1 : lineno;
283283
const char* buf_end = p->tok->fp_interactive ? p->tok->interactive_src_end : p->tok->inp;
284284

285+
if (buf_end < cur_line) {
286+
buf_end = cur_line + strlen(cur_line);
287+
}
288+
285289
for (int i = 0; i < relative_lineno - 1; i++) {
286290
char *new_line = strchr(cur_line, '\n');
287291
// The assert is here for debug builds but the conditional that

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy