* [3.13] gh-130077: Properly match full soft keywords in the parser (GH-135317)
(cherry picked from commit
ff2b5f40c2bf5c71255caac8a743c09ba0758c02)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* Remove line the main-branch commit removed
---------
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Traceback (most recent call last):
SyntaxError: invalid syntax
+# But prefixes of soft keywords should
+# still raise specialized errors
+
+>>> (mat x)
+Traceback (most recent call last):
+SyntaxError: invalid syntax. Perhaps you forgot a comma?
+
From compiler_complex_args():
>>> def f(None=1):
--- /dev/null
+Properly raise custom syntax errors when incorrect syntax containing names
+that are prefixes of soft keywords is encountered. Patch by Pablo Galindo.
Py_ssize_t size;
PyBytes_AsStringAndSize(t->bytes, &the_token, &size);
for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) {
- if (strncmp(*keyword, the_token, size) == 0) {
+ if (strlen(*keyword) == (size_t)size &&
+ strncmp(*keyword, the_token, (size_t)size) == 0) {
return _PyPegen_name_from_token(p, t);
}
}