Skip to content

Commit 3e395f0

Browse files
committed
fixup! bpo-40619: Correctly handle error text and offset for <string> input
1 parent e821e23 commit 3e395f0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/test/test_exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def baz():
229229
'''quux'''
230230
""", 9, 20)
231231
check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4)
232+
check("(1+)", 1, 4)
232233

233234
# Errors thrown by symtable.c
234235
check('x = [(yield i) for i in range(3)]', 1, 5)

Parser/pegen/pegen.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
399399

400400
if (!error_line) {
401401
Py_ssize_t size = p->tok->inp - p->tok->buf;
402-
error_line = PyUnicode_DecodeUTF8(p->tok->buf, size ? size - 1: size, "replace");
402+
error_line = PyUnicode_DecodeUTF8(p->tok->buf,
403+
p->tok->buf[size-1] == '\n' ? size - 1 : size,
404+
"replace");
403405
if (!error_line) {
404406
goto error;
405407
}

0 commit comments

Comments
 (0)