Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a follow-up from https://www.drupal.org/node/2572699#comment-12271753.
The line:
while (--$len >= 0 && ord($string[$len]) >= 0x80 && ord($string[$len]) < 0xC0);
should be more readable.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2911497_3.patch | 755 bytes | Mile23 |
Comments
Comment #3
Mile23Replaced side-effects with do-while.
Comment #4
dawehnerI don't think we should have to do that. #2849669: Fix \Drupal\Component\Utility\Unicode() because of the Symfony mbstring polyfill will basically empty this file completely.
Comment #5
alexpottWell \Drupal\Component\Utility\Unicode::truncateBytes() has no mb_* equivalent so I guess this issue can proceed.
Comment #6
borisson_While this is more readable, I still wouldn't call this simple. However, it is better compared to the situation we had before.
This method has specific unit test coverage that confirms this still works.
That means this can go to RTBC, also based on #5's answer to #4.
Comment #7
alexpottI've added some test cases and found a bug in the difference between the way this works for unicode and non-unicode characters.
I think we should add the following test cases here:
because this explicitly proves the counting backwards is working. I also think we should create a followup to fix the bug when
is set to a negative number. In that issue we should discuss what to do. I think it might be correct just to ensure that $len is positive and deprecate the incorrect negative behaviour. As you can see from the negative behaviour test for unicode it currently incorrectly chops up the string resulting in a � character.