sub basename {
- my($name) = shift;
- _strip_trailing_sep($name);
- (fileparse($name, map("\Q$_\E",@_)))[0];
+ my($path) = shift;
+
+ _strip_trailing_sep($path);
+ my($basename, $dirname) = fileparse( $path, map("\Q$_\E",@_) );
+ $basename = $dirname unless length $basename;
+
+ return $basename;
}
@INC = '../lib';
}
-use Test::More tests => 57;
+use Test::More tests => 60;
BEGIN { use_ok 'File::Basename' }
is(basename('/arma/virumque.cano'), 'virumque.cano');
is(dirname ('/arma/virumque.cano'), '/arma');
is(dirname('arma/'), '.');
- is(dirname('/'), '/');
}
}
+### rt.cpan.org 36477
+{
+ fileparse_set_fstype('Unix');
+ is(dirname('/'), '/');
+ is(basename('/'), '/');
+
+ fileparse_set_fstype('DOS');
+ is(dirname('\\'), '\\');
+ is(basename('\\'), '\\');
+}
+
+
### Test tainting
{
# The empty tainted value, for tainting strings
1;
}
+ fileparse_set_fstype 'Unix';
ok tainted(dirname($TAINT.'/perl/lib//'));
ok all_tainted(fileparse($TAINT.'/dir/draft.book7','\.book\d+'));
}