Skip to content

Strip 8-bit C1 controls in Vt100_Output.write and set_title - #2152

Open
neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:vt100-strip-c1-controls
Open

neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:vt100-strip-c1-controls

Conversation

@neeraj1235476

Copy link
Copy Markdown
Contributor

Vt100_Output.write() is what print_formatted_text() uses for plain text, and its docstring says it removes vt100 escape codes, but it only replaces ESC. The 8-bit C1 introducers (CSI \x9b, OSC \x9d, DCS \x90, ST \x9c, ...) go straight to the terminal, and xterm and VTE-based terminals act on them in UTF-8 mode. So print_formatted_text("\x9b2J\x9b31m...") with untrusted text (a filename, a server response, output sent to a telnet/ssh client) clears the screen or changes styling. set_title() has the same gap: it strips ESC and BEL, but a \x9c in the title ends the OSC early, and anything after it is written as raw output.

write() now also replaces \x80-\x9f with ?, the same as ESC. Most text is ASCII, so an isascii() check keeps that path at a single str.replace. set_title() drops the same range. The layout Screen already shows these characters as <9b> etc., so this only brings the direct-write path in line with it. Tests are added in tests/test_vt100_output.py.

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.

1 participant