Skip to content
Snippets Groups Projects
Commit fa446926 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

more utf8_basename fixes

parent a8c343f2
No related branches found
No related tags found
No related merge requests found
......@@ -64,8 +64,23 @@ class utf8_basename_test extends DokuWikiTest {
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'),
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', '.png', 'bar.test'),
array('/\\bar.test.png', '', 'bar.test.png'),
array('/\\bar.test.png', '.png', 'bar.test'),
// PHP's basename does this too:
array('foo/', '', 'foo'),
array('foo\\', '', 'foo'),
array('foo\\/', '', 'foo'),
array('foo/\\', '', 'foo'),
array('foo.png/', '.png', 'foo'),
array('foo.png\\', '.png', 'foo'),
array('foo.png\\/', '.png', 'foo'),
array('foo.png/\\', '.png', 'foo'),
);
foreach($data as $test){
......
......@@ -91,10 +91,9 @@ if(!function_exists('utf8_basename')){
* @return string
*/
function utf8_basename($path, $suffix=''){
$slashrpos = strrpos($path, '/');
$bslashrpos = strrpos($path, '\\');
$rpos = max($slashrpos === false ? -1 : $slashrpos, $bslashrpos === false ? -1 : $bslashrpos);
$path = substr($path, $rpos+1);
$path = trim($path,'\\/');
$rpos = max(strrpos($path, '/'), strrpos($path, '\\'));
if($rpos) $path = substr($path, $rpos+1);
$suflen = strlen($suffix);
if($suflen && (substr($path, -$suflen) == $suffix)){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment