diff options
author | Michael Hamann <michael@content-space.de> | 2012-07-29 12:09:31 +0200 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2012-07-29 12:09:31 +0200 |
commit | a8c343f2838765f8034ee6b91263b1b417f3a7ec (patch) | |
tree | 47fed482e99f6b4d6bb7ff0caff5c8c57cff1ac3 | |
parent | 420addb2e4aefb77d089e776672d40c18f86b2ac (diff) | |
download | rpg-a8c343f2838765f8034ee6b91263b1b417f3a7ec.tar.gz rpg-a8c343f2838765f8034ee6b91263b1b417f3a7ec.tar.bz2 |
Fix utf8_basename for files in the root directory
-rw-r--r-- | _test/tests/inc/utf8_basename.test.php | 4 | ||||
-rw-r--r-- | inc/utf8.php | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/_test/tests/inc/utf8_basename.test.php b/_test/tests/inc/utf8_basename.test.php index 62d006088..475b7ada8 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 273c344c6..e3e7e8c1a 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)){ |