Commit 993f5a48 authored by Steven Wittens's avatar Steven Wittens

- #41555: truncate_utf8 infinite loop on invalid utf-8

parent 88490f64
......@@ -193,12 +193,16 @@ function truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE) {
return $string;
}
if ($wordsafe) {
$end = $len;
while (($string[--$len] != ' ') && ($len > 0)) {};
if ($len == 0) {
$len = $end;
}
}
if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
return substr($string, 0, $len) . ($dots ? ' ...' : '');
}
while (ord($string[--$len]) < 0xC0) {};
while (--$len >= 0 && ord($string[$len]) >= 0x80 && ord($string[$len]) < 0xC0) {};
return substr($string, 0, $len) . ($dots ? ' ...' : '');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment