mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
dbbb7401a39bcd9d529fccef9f7dfaa41fa82422
This PR was merged into the 2.x branch.
Discussion
----------
Use null rather than specific length for 'to the end' in mb_substr
We use Twig with a ISO-8859-15 charset and noticed the 'capitalize'-method only yielded the first character of a string. I.e. "abcd" became "A" rather than "Abcd".
This was due to a change in the way mb_substr is used. Appearantly, using 2147483647 as a length to indicate 'everything to the end' only works with UTF-8 (and possibly other multibyte charsets). It probably triggers some internal overflow in php for at least ASCII and ISO-8859-15.
Luckily, an easy fix is available since PHP 5.4.8: just use 'null'
See these two tests for which version does what:
(old) https://3v4l.org/qdpIK
(new) https://3v4l.org/kivqK
I also used null in the slice-method. While it did not suffer from this same issue, it did an unnecessary mb_strlen. And there might be similar overflow issues with negative values of $start, but I didn't actually test that.
Commits
-------
3bea610e Use null rather than specific length for 'all characters to the end' with mb_substr
Twig, the flexible, fast, and secure template language for PHP ============================================================== Twig is a template language for PHP, released under the new BSD license (code and documentation). Twig uses a syntax similar to the Django and Jinja template languages which inspired the Twig runtime environment. More Information ---------------- Read the `documentation`_ for more information. .. _documentation: http://twig.sensiolabs.org/documentation
Description
Languages
PHP
99.9%