Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! bpo-40619: Correctly handle error text and offset for <string>…
… input
  • Loading branch information
pablogsal committed May 14, 2020
commit 3e395f06792cc327577afcf5148bdb0edee028e1
1 change: 1 addition & 0 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def baz():
'''quux'''
""", 9, 20)
check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4)
check("(1+)", 1, 4)

# Errors thrown by symtable.c
check('x = [(yield i) for i in range(3)]', 1, 5)
Expand Down
4 changes: 3 additions & 1 deletion Parser/pegen/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,

if (!error_line) {
Py_ssize_t size = p->tok->inp - p->tok->buf;
error_line = PyUnicode_DecodeUTF8(p->tok->buf, size ? size - 1: size, "replace");
error_line = PyUnicode_DecodeUTF8(p->tok->buf,
p->tok->buf[size-1] == '\n' ? size - 1 : size,
"replace");
Comment thread
pablogsal marked this conversation as resolved.
Outdated
if (!error_line) {
goto error;
}
Expand Down