diff --git a/_test/tests/inc/utf8_basename.test.php b/_test/tests/inc/utf8_basename.test.php index 62d0060884e55aa4ff0524ad353a0bc1b99f4084..475b7ada85234840b136b1b1f2a6da8a52117b6f 100644 --- a/_test/tests/inc/utf8_basename.test.php +++ b/_test/tests/inc/utf8_basename.test.php @@ -62,6 +62,10 @@ class utf8_basename_test extends DokuWikiTest { array('bar.test.png', '', 'bar.test.png'), array('bar.test.png', '.png', 'bar.test'), + + array('/bar.test.png', '', 'bar.test.png'), + array('\\bar.test.png', '', 'bar.test.png'), + array('/bar.test.png', '.png', 'bar.test'), ); foreach($data as $test){ diff --git a/inc/utf8.php b/inc/utf8.php index 273c344c663a9fe477dabc069127be464f310a9b..e3e7e8c1a7c9b01b1ee34e667f4b95609b35d141 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -91,8 +91,10 @@ if(!function_exists('utf8_basename')){ * @return string */ function utf8_basename($path, $suffix=''){ - $rpos = max(strrpos($path, '/'), strrpos($path, '\\')); - if($rpos) $path = substr($path, $rpos+1); + $slashrpos = strrpos($path, '/'); + $bslashrpos = strrpos($path, '\\'); + $rpos = max($slashrpos === false ? -1 : $slashrpos, $bslashrpos === false ? -1 : $bslashrpos); + $path = substr($path, $rpos+1); $suflen = strlen($suffix); if($suflen && (substr($path, -$suflen) == $suffix)){