8000 bpo-45494: Fix parser crash when reporting errors involving invalid c… · python/cpython@a106343 · GitHub
[go: up one dir, main page]

Skip to content

Commit a106343

Browse files
authored
bpo-45494: Fix parser crash when reporting errors involving invalid continuation characters (GH-28993)
There are two errors that this commit fixes: * The parser was not correctly computing the offset and the string source for E_LINECONT errors due to the incorrect usage of strtok(). * The parser was not correctly unwinding the call stack when a tokenizer exception happened in rules involving optionals ('?', [...]) as we always make them return valid results by using the comma operator. We need to check first if we don't have an error before continuing.
1 parent bda69ab commit a106343

File tree

5 files changed

+137
-123
lines changed

5 files changed

+137
-123
lines changed

Lib/test/test_exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def check(self, src, lineno, offset, encoding='utf-8'):
209209
src = src.decode(encoding, 'replace')
210210
line = src.split('\n')[lineno-1]
211211
self.assertIn(line, cm.exception.text)
212+
213+
def test_error_offset_continuation_characters(self):
214+
check = self.check
215+
check('"\\\n"(1 for c in I,\\\n\\', 2, 2)
212216

213217
def testSyntaxErrorOffset(self):
214218
check = self.check
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix parser crash when reporting errors involving invalid continuation
2+
characters. Patch by Pablo Galindo.

0 commit comments

Comments
 (0)
0