Skip to content

fix(tui): harden collapse.lines against non-string content - #2057

Open
YOMXXX wants to merge 1 commit into
XiaomiMiMo:mainfrom
YOMXXX:fix/collapse-lines-nonstring
Open

fix(tui): harden collapse.lines against non-string content#2057
YOMXXX wants to merge 1 commit into
XiaomiMiMo:mainfrom
YOMXXX:fix/collapse-lines-nonstring

Conversation

@YOMXXX

@YOMXXX YOMXXX commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1952. TypeError: A.replace is not a function (minified A = content) when collapse.lines receives a truthy non-string value.

Root cause: packages/opencode/src/cli/cmd/tui/util/collapse.ts lines() guard if (!content) return [] only catches falsy values — a truthy non-string (number/object) passes and content.replace is undefined → crash. Tool output / patch content rendered in the TUI can be a non-string under unusual model output.

Fix: tighten the guard to reject any non-string while preserving the empty-string → [] behavior (which rows("") depends on):

export function lines(content: unknown) {
  if (typeof content !== "string" || content === "") return []
  return content.replace(/\n$/, "").split("\n")
}

Test Plan

  • New collapse.lines tests: non-string truthy → []; undefined/null/""[]; strings still split with trailing newline stripped.
  • bun test test/cli/tui/collapse.test.ts — 19 pass.
  • bun typecheck — clean.

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.

TypeError: A.replace is not a function. (In 'A.replace(/\n$/,"")', 'A.replace' is undefined)

1 participant