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
Fix for mb function overload mb_substr acting different #1453
Conversation
Is it possible to add a test that covers this issue? |
When setting the option in ini_set('mbstring.func_overload', '2'); all goes well. When setting it directly in the (While odd this also seems the case for some users running Windows & Apache2 who try to set it the Therefore I cannot provide a test since it only happends when setting it in the |
@@ -702,7 +702,12 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese | |||
$item = (string) $item; | |||
|
|||
if (function_exists('mb_get_info') && null !== $charset = $env->getCharset()) { | |||
return mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset); | |||
$r = mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset); | |||
if (false === $r) { |
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.
What about just casting to a string? return (string) mb_substr(...);
…mbstring.func_overload set 2 in php.ini
@fabpot I agree on the cast over the result check, please last commit :) |
A small thing: you inadvertently changed the file rights to 0755, can you revert this change? |
Thank you @1emming. |
When bug hunting https://github.com/fabpot/Twig/issues/1428 I ran into an issue.
I started out by changing my
php.ini
for thecli
enviroment, I've added:mbstring.func_overload = 2
Later I tested with adding and removing:
mbstring.internal_encoding = 'UTF-8'
It turns out
mb_substr
returnsfalse
and not''
when doing something like this:I'm not sure this will fix 1428 since I don't have enough information for this, but this PR should at least fix one issue.