Fabien Potencier dbbb7401a3 bug #2366 Use null rather than specific length for 'to the end' in mb_substr (arjenm)
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
2017-01-17 07:18:35 -08:00
2017-01-10 14:07:32 -08:00
2017-01-04 14:05:59 -08:00
2017-01-11 11:39:41 -08:00
2017-01-10 14:08:27 -08:00
2017-01-02 12:22:20 -08:00

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
Languages
PHP 99.9%