Skip to content

truncateMiddle returns the whole string when maxLength is 1 or 2 #34395

Closed

Description

@Osamaali313

Description

truncateMiddle (packages/tui/src/util/locale.ts) returns the whole string — longer than the input — when maxLength is 1 or 2. At those widths keepEnd is 0, and str.slice(-0) slices from index 0 (returns everything) instead of nothing. The run splash detail line (splash.ts, which calls truncateMiddle(detail, Math.max(1, width - body_left))) can overflow on very narrow terminals.

Steps to reproduce

truncateMiddle("hello-world", 1) returns "…hello-world" (length 12) and truncateMiddle("hello-world", 2) returns "h…hello-world" (length 13). Expected "…" and "h…".

Activity

  1. github-actions commented on Jun 29, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. Osamaali313 commented on Jun 29, 2026

    @Osamaali313
    Author

    Closing as a duplicate of #20880 (same truncateMiddle / slice(-0) bug). The fix is in #34482, now linked to #20880.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions