Skip to content

fix: return empty string when truncateWithEllipsis maxLength <= 0 - #23195

Open
prudhvirajkonda8-bot wants to merge 1 commit into
desktop:developmentfrom
prudhvirajkonda8-bot:fix/truncate-with-ellipsis-negative-length
Open

prudhvirajkonda8-bot wants to merge 1 commit into
desktop:developmentfrom
prudhvirajkonda8-bot:fix/truncate-with-ellipsis-negative-length

Conversation

@prudhvirajkonda8-bot

Copy link
Copy Markdown

Description

Fixes #23194.

In app/src/lib/truncate-with-ellipsis.ts, truncateWithEllipsis slices characters with characters.slice(0, maxLength). When maxLength is non-positive or negative (such as when dynamically computing space in constrained headers or branch labels), JavaScript's Array.prototype.slice interprets negative values as offsets from the end of the array, returning a long slice with an ellipsis appended.

This PR adds an early return returning '' when maxLength <= 0.

Tests

  • Added unit test in app/test/unit/truncate-with-ellipsis-test.ts verifying that maxLength <= 0 returns ''.
  • All unit tests pass.

When maxLength is non-positive, characters.slice(0, maxLength)
previously treated it as an offset from the end of the array,
returning a string with an ellipsis. Guard against non-positive
lengths and return an empty string.
@prudhvirajkonda8-bot
prudhvirajkonda8-bot requested a review from a team as a code owner November 17, 2026 16:40
@prudhvirajkonda8-bot
prudhvirajkonda8-bot requested review from niik and a balanced review from Copilot November 17, 2026 16:40
@github-actions github-actions Bot added external Pull request originating outside of the Desktop core team needs-triage ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed needs-triage labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your pull request! While it doesn't meet all of our standard requirements, it appears to be a small, focused contribution and has been routed to the team for review.

Note: We still encourage linking to an issue with the help wanted label when possible, as it helps us prioritize and track contributions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change handling non-positive truncation limits.

No open issues 🎉

What changed in this PR

Fixes #23194 by making GitHub Desktop’s truncateWithEllipsis helper return an empty string for non-positive length limits, avoiding backward slicing and unwanted ellipses.

Changes:

  • Add an early return when maxLength <= 0.
  • Add regression assertions for zero and negative limits.
File Description
app/​test/​unit/​truncate-with-ellipsis-test.ts Tests empty-string results for limits of 0, -1, and -5.
app/​src/​lib/​truncate-with-ellipsis.ts Returns an empty string before slicing when the limit is non-positive.

Review effort: Balanced

This branch has not been deployed

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

Labels

external Pull request originating outside of the Desktop core team ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

truncateWithEllipsis slices backwards and produces long string when passed non-positive maxLength

2 participants