Skip to content

fix: don't call winterm for OSC title codes when not converting (#407) - #425

Open
patchwright wants to merge 1 commit into
tartley:masterfrom
patchwright:fix/osc-title-no-convert
Open

fix: don't call winterm for OSC title codes when not converting (#407)#425
patchwright wants to merge 1 commit into
tartley:masterfrom
patchwright:fix/osc-title-no-convert

Conversation

@patchwright

Copy link
Copy Markdown

Fixes #407.

Problem

In convert_osc, winterm.set_title() is called unconditionally when an OSC title sequence is seen. Every other winterm call is gated on self.convert (convert_ansi checks if self.convert:, get_win32_calls checks self.convert and winterm) — but this one isn't.

On non-Windows platforms winterm is None. When strip=True and convert=False (e.g. running without a PTY on Linux, where init() strips sequences but does not convert), writing a title sequence reaches winterm.set_title and crashes:

AnsiToWin32.write -> write_and_convert -> convert_osc -> winterm.set_title
AttributeError: 'NoneType' object has no attribute 'set_title'

(call path as traced in #407 by the reporter.)

Fix

Guard the call with self.convert and winterm, matching the pattern already used in get_win32_calls. The OSC sequence is still stripped from the output in all cases (that happens before the guard); only the win32 title call is now correctly skipped when not converting.

Tests

Added test_osc_codes_not_converted_when_stripping: with winterm patched to None and strip=True, convert=False, writing a title OSC sequence must not raise. It fails on main with the exact AttributeError above and passes with the fix. Existing test_osc_codes (the convert=True path) is unchanged. Full suite: 39 passed, 14 skipped.

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