Repository navigation
fix: return empty string when truncateWithEllipsis maxLength <= 0 - #23195
Open
prudhvirajkonda8-bot wants to merge 1 commit into
Open
prudhvirajkonda8-bot wants to merge 1 commit into
prudhvirajkonda8-bot wants to merge 1 commit into
Conversation
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
requested review from
niik
and
a balanced review from Copilot
November 17, 2026 16:40
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 |
Contributor
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #23194.
In
app/src/lib/truncate-with-ellipsis.ts,truncateWithEllipsisslices characters withcharacters.slice(0, maxLength). WhenmaxLengthis non-positive or negative (such as when dynamically computing space in constrained headers or branch labels), JavaScript'sArray.prototype.sliceinterprets 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
''whenmaxLength <= 0.Tests
app/test/unit/truncate-with-ellipsis-test.tsverifying thatmaxLength <= 0returns''.