diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-02-09 08:56:11 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-02-09 08:56:11 +0000 |
commit | 993f5a486527b63702a17513b8c6b35e09da9c08 (patch) | |
tree | ff8241fb5ce159d76f6356d4df3fbc0eefd50e8a /includes/unicode.inc | |
parent | 88490f6413ea2cfc667eb634c8a29478b89aa94e (diff) | |
download | brdo-993f5a486527b63702a17513b8c6b35e09da9c08.tar.gz brdo-993f5a486527b63702a17513b8c6b35e09da9c08.tar.bz2 |
- #41555: truncate_utf8 infinite loop on invalid utf-8
Diffstat (limited to 'includes/unicode.inc')
-rw-r--r-- | includes/unicode.inc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/includes/unicode.inc b/includes/unicode.inc index 54fe7bb8b..cd8285514 100644 --- a/includes/unicode.inc +++ b/includes/unicode.inc @@ -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 ? ' ...' : ''); } |