]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-112388: Fix an error that was causing the parser to try to overwrite tokeni...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 27 Nov 2023 19:02:57 +0000 (20:02 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 19:02:57 +0000 (19:02 +0000)
gh-112388: Fix an error that was causing the parser to try to overwrite tokenizer errors (GH-112410)
(cherry picked from commit 2c8b19174274c183eb652932871f60570123fe99)

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Lib/test/test_syntax.py
Misc/NEWS.d/next/Core and Builtins/2023-11-25-22-58-49.gh-issue-112388.MU3cIM.rst [new file with mode: 0644]
Parser/pegen_errors.c

index 5183aaa506f8728d289acefeb64486646684c370..3005d0547fec0b36aab425dc7ccaa372bd911845 100644 (file)
@@ -2309,6 +2309,7 @@ func(
 
     def test_invisible_characters(self):
         self._check_error('print\x17("Hello")', "invalid non-printable character")
+        self._check_error(b"with(0,,):\n\x01", "invalid non-printable character")
 
     def test_match_call_does_not_raise_syntax_error(self):
         code = """
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-11-25-22-58-49.gh-issue-112388.MU3cIM.rst b/Misc/NEWS.d/next/Core and Builtins/2023-11-25-22-58-49.gh-issue-112388.MU3cIM.rst
new file mode 100644 (file)
index 0000000..1c82be2
--- /dev/null
@@ -0,0 +1,2 @@
+Fix an error that was causing the parser to try to overwrite tokenizer
+errors. Patch by pablo Galindo
index e832422ab1c8fe9d2bbebd5c51380a1ebd806c59..c13ba97a2480ca97578919918bf4c12eebf5118d 100644 (file)
@@ -217,6 +217,10 @@ exit:
 void *
 _PyPegen_raise_error(Parser *p, PyObject *errtype, int use_mark, const char *errmsg, ...)
 {
+    // Bail out if we already have an error set.
+    if (p->error_indicator && PyErr_Occurred()) {
+        return NULL;
+    }
     if (p->fill == 0) {
         va_list va;
         va_start(va, errmsg);