summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2021-11-20 18:28:28 (GMT)
committerGitHub <noreply@github.com>2021-11-20 18:28:28 (GMT)
commit81f4e116ef7d30ef6e2041c2d6cf29af511a3a02 (patch)
tree73b411df7a7dc4c50c78b0fa19e063d1bdbd72f1 /Parser
parent7a1d9325287a39528b795b1e8037146777abfe3e (diff)
downloadcpython-81f4e116ef7d30ef6e2041c2d6cf29af511a3a02.zip
cpython-81f4e116ef7d30ef6e2041c2d6cf29af511a3a02.tar.gz
cpython-81f4e116ef7d30ef6e2041c2d6cf29af511a3a02.tar.bz2
bpo-45811: Improve error message when source code contains invisible control characters (GH-29654)
Diffstat (limited to 'Parser')
-rw-r--r--Parser/tokenizer.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index f281c42..69d2c08 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -2045,6 +2045,12 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end)
break;
}
+ if (!Py_UNICODE_ISPRINTABLE(c)) {
+ char hex[9];
+ (void)PyOS_snprintf(hex, sizeof(hex), "%04X", c);
+ return syntaxerror(tok, "invalid non-printable character U+%s", hex);
+ }
+
/* Punctuation character */
*p_start = tok->start;
*p_end = tok->cur;