diff options
author | Stefan Giehl <stefan@piwik.org> | 2017-12-13 23:49:21 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2017-12-13 23:49:21 +0300 |
commit | 56f7bc5a879e868436c4286cb4cfb6983d12bf54 (patch) | |
tree | 6ea24ff036561415ee66c6f1985afc02503a9bf3 /core | |
parent | f91f646c2f5df8d4432aa86db2a2f4a3d9a50452 (diff) |
Improves truncate twig filter (#12347)
* respect encoded entities in truncate filter
* adds some simple tests
Diffstat (limited to 'core')
-rwxr-xr-x | core/Twig.php | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/core/Twig.php b/core/Twig.php index c36452055b..24fd09eec2 100755 --- a/core/Twig.php +++ b/core/Twig.php @@ -25,11 +25,11 @@ use Twig_SimpleTest; function piwik_filter_truncate($string, $size) { - if (strlen($string) < $size) { + if (Common::mb_strlen(html_entity_decode($string)) <= $size) { return $string; } else { - $array = str_split($string, $size); - return array_shift($array) . "..."; + preg_match('/^(&(?:[a-z\d]+|#\d+|#x[a-f\d]+);|.){'.$size.'}/i', $string, $shortenString); + return reset($shortenString) . "..."; } } |