-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[String] Fix ellipsis of truncate when not using cut option #37054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -1450,6 +1450,7 @@ public static function provideTruncate() | |||
['foobar...', 'foobar foo', 6, '...', false], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort-of unrelated, but what happens with ['???', 'foobar', 5, '...'],
ie. if ($length + $ellipsisLength) > $stringLength
?
It should return the full string then, possibly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean, please provide a test case if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure whether the length provided to the method is including or excluding the ellipsis. But apparently it is, so the case I talked about can't happen here.
So nvm then 👍
4d0133c
to
a2ee6c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the implementation to make more local, good catch overall.
@@ -1450,6 +1450,7 @@ public static function provideTruncate() | |||
['foobar...', 'foobar foo', 6, '...', false], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean, please provide a test case if you want.
Thank you @duboiss. |
Since 5.1, we can use a cut option on truncate.
But with this option, we don't have the expected behavior when the entire chain is returned.
Currently:
u('Lorem Ipsum')->truncate(8, '…', false); // 'Lorem Ipsum...'
Instead of:
u('Lorem Ipsum')->truncate(8, '…', false); // 'Lorem Ipsum'
Thanks to @jmsche for his help.