Support truncation of mulitbyte srings
authornirgal <nirgal@users.noreply.github.com>
Fri, 4 Oct 2019 08:58:02 +0000 (08:58 +0000)
committerRobert Treat <rob@xzilla.net>
Sun, 13 Oct 2019 00:27:23 +0000 (20:27 -0400)
This fixes https://sourceforge.net/p/phppgadmin/bugs/422/ :
substr truncates on a byte-level, sometimes within a multi-byte character. This resulted in the whole string sometime not being displayed. See the original bug report for a way to reproduce.

Please note that this requires php-mbstring to be installed. This is usually the case, but the dependency should be described in the INSTALL file or something.

classes/Misc.php

index 87a5eb6f6dee573a28e3714f5988c74a01119cd8..9939502e1d7ce0f21b894dd91197eea8d236521b 100644 (file)
                        if (isset($params['clip']) && $params['clip'] === true) {
                                $maxlen = isset($params['cliplen']) && is_integer($params['cliplen']) ? $params['cliplen'] : $conf['max_chars'];
                                $ellipsis = isset($params['ellipsis']) ? $params['ellipsis'] : $lang['strellipsis'];
-                               if (strlen($str) > $maxlen) {
-                                       $str = substr($str, 0, $maxlen-1) . $ellipsis;
+                               if (mb_strlen($str, 'UTF-8') > $maxlen) {
+                                       $str = mb_substr($str, 0, $maxlen-1, 'UTF-8') . $ellipsis;
                                }
                        }