Repository navigation
Conversation
banghamid
force-pushed
the
fix/text-helper-ellipsize
branch
from
November 21, 2026 13:35
f174d04 to
14e5472
Compare
banghamid
marked this pull request as ready for review
November 21, 2026 13:51
michalsn
requested changes
Nov 21, 2026
michalsn
left a comment
Member
There was a problem hiding this comment.
We also need a changelog entry.
| } else { | ||
| $end = mb_substr($str, -($maxLength - mb_strlen($beg))); | ||
| } | ||
| $position = max(0.0, min(1.0, (float) $position)); |
Member
There was a problem hiding this comment.
Suggested change
| $position = max(0.0, min(1.0, (float) $position)); | |
| $position = max(0.0, min(1.0, $position * 1.0)); |
Could we preserve the TypeError for non-numeric strings? It would be nice to have a test for this too.
Contributor
Author
There was a problem hiding this comment.
Done in 75e8881 — switched to $position * 1.0 to preserve the TypeError for non-numeric strings and added testEllipsizeInvalidPositionThrowsTypeError().
Contributor
Author
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
In
system/Helpers/text_helper.php,ellipsize()had two bugs in how it handled$position:$positionwas clamped to1after$begwas already sliced using$maxLength * $position:$position > 1(e.g.2or1.5),$begtook more than$maxLengthcharacters and$endreceived a positive length, duplicating the beginning of the string:ellipsize('this is my string', 10, 2)returned'this is my string…this is'instead of'this is my…'.$position === 1used strict integer comparison even thoughellipsize()documents@param float|int $position. Passing1.0(float) failed the check and fell into theelsebranch, computingmb_substr($str, -0)(equivalent tomb_substr($str, 0)) and appending the entire original string after the ellipsis:ellipsize('this is my string', 10, 1.0)returned'this is my…this is my string'instead of'this is my…'.This PR:
$positionto[0.0, 1.0]viamax(0.0, min(1.0, $position * 1.0))before slicing$beg, handling float1.0identically to integer1while preserving nativeTypeErrorfor non-numeric types.$endwhen$remaining > 0($maxLength - mb_strlen($beg)), preventing duplicated string content when$position >= 1.0.tests/system/Helpers/TextHelperTest.php:testEllipsizePositionEdgeCases()covering edge cases1.0,2,1.5, and-0.5.testEllipsizeInvalidPositionThrowsTypeError()verifyingTypeErrorfor non-numeric position arguments.docs/changelogs/v4.7.7.md.Checklist: