Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: strip control characters and cap length of window titles - #195

Open
livenson wants to merge 1 commit into
coder:mainfrom
waldur:fix/window-title-sanitize
Open

livenson wants to merge 1 commit into
coder:mainfrom
waldur:fix/window-title-sanitize

Conversation

@livenson

Copy link
Copy Markdown

Summary

onTitleChange delivered the OSC 0/2 payload exactly as a regex matched it in the raw data: including C0 control characters, and with no length limit. Embedders typically put the title straight into document.title or their own UI.

Change

  • Drop C0 control characters and DEL from the title, as a VT parser ignores them inside an OSC string.
  • Ignore titles longer than 255 UTF-8 bytes, the limit native Ghostty applies (windowTitle in src/termio/stream_handler.zig).

The WASM currently ignores .window_title, so tracking the title there would be the fuller fix; this keeps the change in TypeScript. #169 also refactors checkForTitleChange, and #176 adds title tests to terminal.test.ts; happy to rebase onto whichever lands first.

Testing

  • New cases in terminal.test.ts: control characters are stripped, and an over-long title is ignored while the previous one is kept.
  • bun run fmt && bun run lint && bun run typecheck && bun test && bun run build all pass, with tests run against a WASM built from this tree (Zig 0.15.2).
  • In headless Chromium, with a build containing this change, ESC]2;safe\rspoofed\btitle BEL produces the title safespoofedtitle, and a 256-byte title leaves it unchanged.

The window title set with OSC 0 or 2 comes from terminal output, and
embedders typically show it in the page or window title. The title was
taken from the raw data with a regex that also captured C0 control
characters and did not bound its length.

Drop C0 control characters and DEL from the title, as a VT parser ignores
them inside an OSC string, and ignore titles longer than 255 UTF-8 bytes,
the limit native Ghostty applies (windowTitle in termio/stream_handler.zig).
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