coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 bridging => Topic started by: Pit on December 05, 2005, 11:54:23 PM

Title: Possible bug in mb.inc.php
Post by: Pit on December 05, 2005, 11:54:23 PM
There seems to be a bug in include/mb.inc.php function mb_substr():

While trying to bridge cpg to ipb I have noticed that all group names of ipb have been imported only with the first character. This happened on a server where I didn't have activated mbstring library in php.ini. Testing the error in my local environment I found the bug in mb.inc.php.

In the original code of mb_substr you call array_slice always with parameter length (here $end) even when that parameter is null. In my php installation (4.4.1)  array_slice returns only the $start element of the array instead of the entire rest of it.

        function mb_substr($str, $start, $end=null) {
                global $mb_utf8_regex;
                preg_match_all("#$mb_utf8_regex".'|[\x00-\x7F]#', $str, $str);
                $str = array_slice($str[0], $start, $end);
                return implode('', $str);
        }


To avoid this behavior I have had to modify the function:
        function mb_substr($str, $start, $end=null) {
                global $mb_utf8_regex;
                preg_match_all("#$mb_utf8_regex".'|[\x00-\x7F]#', $str, $str);
                if ($end == null)
                    $str = array_slice($str[0], $start);
                else
                    $str = array_slice($str[0], $start, $end);
                return implode('', $str);
        }


Perhaps you can verify this as a bug.
Title: Re: Possible bug in mb.inc.php
Post by: Nibbler on December 06, 2005, 12:05:21 AM
Already fixed. See http://forum.coppermine-gallery.net/index.php?topic=24201.msg111341#msg111341