Skip to content

EllipsisMiddleTruncate exceeds requested width when only the ellipsis fits #722

Description

@MateehUllah

EllipsisMiddleTruncate returns more characters than the requested width when available_space is 3. It also modifies strings that already fit exactly within the specified width.

Steps to reproduce

from fire import formatting

print(formatting.EllipsisMiddleTruncate('abcdefghij', 3, 80))
# Actual: '...abcdefghij'
# Expected: '...'

print(formatting.EllipsisMiddleTruncate('abcd', 4, 80))
# Actual: '...d'
# Expected: 'abcd'

Cause

The expression text[-second_half_len:] returns the entire string when second_half_len is zero. The no-truncation check also uses < instead of <=.

Expected behavior

Output should respect the available width, and strings that already fit should remain unchanged.

Verification

Reproduced using the implementation from fire/formatting.py.

Activity

  1. hugosmoreira commented on Oct 26, 2026

    @hugosmoreira

    I'd like to work on this. I reproduced both examples on current master. I'll add regression tests for the ellipsis-sized and exact-fit boundaries, fix the middle truncation logic, and preserve the existing fallback to the full line width when fewer than three characters are available.

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

Metadata

Metadata

Assignees

No one assigned

    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

      ⌂ Proxy