Skip to content

Fixes SyntaxError (U+2029) after pasting a multi-line script - #672

Merged
joern274 merged 2 commits into
emsec:masterfrom
horhulenko:fix/python-console-paste
Nov 3, 2026
Merged

joern274 merged 2 commits into
emsec:masterfrom
horhulenko:fix/python-console-paste

Conversation

@horhulenko

Copy link
Copy Markdown
Contributor

Resolves #662

Pasted lines reach the console separated by U+2029 instead of \n, so a pasted snippet never parsed. On top of that, a failed parse was never cleared, which made every later parse fail as well, so the console stayed at ... for good, even for a plain for loop.

Now line breaks are converted before parsing, and a failed parse no longer breaks the next one.

test case before after
paste the snippet from #662 stuck at ... runs
for i in [1,2,3]: / print(i) stuck at ... prints 1 2 3
a = = 1 stuck at ... SyntaxError, console keeps working
image image

joern274
joern274 previously approved these changes Nov 3, 2026

@joern274 joern274 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for PR #672, which covered three bugs that existed at the time the PR was created: line breaks arriving as U+2029, which caused misleading error messages; a missing clear after a failed parse; and a memory leak caused by not releasing the parse result. That was good work! We stumbled over the same problems resolving unrelated Python console issues (see changelog). The bugs mentioned above are resolved by now. Your PR confirms that we came to the same diagnosis. Another improvement came from an external contributor introducing codeop to evaluate the console input. Compound multi-line input like for i in range(10):\n print(i) is now parsed and executed without a problem.

What has not been merged from PR #672 so far is the feature to paste several independent statements at once. I will merge it now. However, there is one caveat: Once user start to paste any number of independent statements at once, they will for sure complain about problems editing the pasted lines, poor navigation, and the lack of syntax highlighting.

What I recommend : The documentation should point out that pasting several independent statements into the Python console is not the recommended strategy. They should paste it into an unnamed Python editor tab instead.

@joern274
joern274 merged commit 305763a into emsec:master Nov 3, 2026
5 checks passed
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.

Python Console: pasting a multi-line script fails with "SyntaxError: invalid non-printable character U+2029"

2 participants