Skip to content

Commit 88f4ec8

Browse files
authored
[3.9] bpo-45494: Fix parser crash when reporting errors involving invalid continuation characters (GH-28993) (#29071)
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.. (cherry picked from commit a106343) Co-authored-by: Pablo Galindo Salgado <[email protected]> NOTE: unlike the cherry-picked original, this commit points at a crazy location due to a bug in the tokenizer that required a big refactor in 3.10 to fix. We are leaving as-is for 3.9.
1 parent 50e8b2f commit 88f4ec8

File tree

5 files changed

+103
-89
lines changed

5 files changed

+103
-89
lines changed

Lib/test/test_exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def check(self, src, lineno, offset, encoding='utf-8'):
193193
line = src.split('\n')[lineno-1]
194194
self.assertIn(line, cm.exception.text)
195195

196+
def test_error_offset_continuation_characters(self):
197+
check = self.check
198+
check('"\\\n"(1 for c in I,\\\n\\', 3, 22)
199+
196200
def testSyntaxErrorOffset(self):
197201
check = self.check
198202
check('def fact(x):\n\treturn x!\n', 2, 10)
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)