Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-45811: Improve error message when source code contains invisible control characters #29654

Merged
merged 1 commit into from
Nov 20, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Nov 20, 2021

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am keeping the error simple to keep it consistent with invalid non-printable characters in names

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@pablogsal
Copy link
Member Author

Example:

❯ ./python -c "eval('print\x16(\"Hello\")')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1
    print("Hello")
         ^
SyntaxError: invalid non-printable character U+0016

lel.py Outdated
Comment on lines 1 to 2
# -*- coding: cp437 -*-
"¢¢¢¢¢¢" + f(4, x for x in range(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is adding this to the repository root intended? What does it do?

Copy link
Member Author

@pablogsal pablogsal Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not intended, I forgot to push the commit that deleted this file

@pablogsal pablogsal merged commit 81f4e11 into python:main Nov 20, 2021
@pablogsal pablogsal deleted the bpo-45811 branch November 20, 2021 18:28
remykarem pushed a commit to remykarem/cpython that referenced this pull request Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants