Skip to content

Return an ordered empty range when trim_range receives only whitespace #548

Closed

Description

@LunaStev

trim_range combines trim_left_index and trim_right_index without reconciling an empty result. For three spaces, the helpers intentionally return 3 and 0 respectively; trim_range therefore exposes start=3, end=0. A caller calculating the trimmed length as end-start gets -3 rather than an empty range.

The individual helper behavior is already asserted by shared/test99 and need not change. The missing behavior belongs in the combined range API.

Code evidence:

Acceptance:

  • Normalize the combined empty result to an ordered zero-length range, with a short comment stating which empty offset is returned.
  • Cover empty input, all spaces, mixed supported whitespace, padded content and content without whitespace.
  • Assert 0 <= start <= end <= input length and preserve the existing individual left/right helper results.
  • Do not expand this patch into changing the set of whitespace characters or adding string dependencies.

Audit status: static source inspection against canonical master ea74c2dafc31da876e5561f2d176ba719f5a0458 on 2026-09-10. No compiler build, test execution, implementation change or local reproduction was performed for this report. The examples describe the source-derived behavior to verify when implementing the fix.

Activity

  1. added
    bug
    good first issue
    on Sep 10, 2026
  2. self-assigned this
    on Sep 24, 2026
  3. added a commit that references this issue on Sep 24, 2026
    01955d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions