Skip to content

Fix AttributeError in convert_osc when winterm is None - #417

Open
worksbyfriday wants to merge 1 commit into
tartley:masterfrom
worksbyfriday:fix-osc-crash-on-linux
Open

Fix AttributeError in convert_osc when winterm is None#417
worksbyfriday wants to merge 1 commit into
tartley:masterfrom
worksbyfriday:fix-osc-crash-on-linux

Conversation

@worksbyfriday

Copy link
Copy Markdown

Summary

Fixes #407.

On non-Windows platforms, winterm is None. When write() receives text containing OSC title-setting sequences (e.g., \033]0;title\a) and strip=True, convert_osc() unconditionally calls winterm.set_title(), which crashes with:

AttributeError: 'NoneType' object has no attribute 'set_title'

Reproduction:

from colorama.ansitowin32 import AnsiToWin32
import io

stream = io.StringIO()
conv = AnsiToWin32(stream, convert=False, strip=True)
conv.write('\033]0;test title\a')  # crashes

Fix

Added a self.convert and winterm guard before calling winterm.set_title(), consistent with the existing pattern used in get_win32_calls() (line 132) and call_win32().

Test

Added test_osc_codes_without_winterm that verifies OSC sequences don't crash when winterm is None.

On non-Windows platforms (where winterm is None), calling
write() with OSC title-setting sequences crashes with
AttributeError: 'NoneType' object has no attribute 'set_title'
when strip=True and convert=False.

Add a guard consistent with the existing pattern used in
get_win32_calls() and call_win32().

Fixes tartley#407
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.

winterm incorrectly called on Linux when strip == True

1 participant