summaryrefslogtreecommitdiff
path: root/lib/File
diff options
context:
space:
mode:
authorMichael G. Schwern <schwern@pobox.com>2005-07-07 07:16:01 -0700
committerSteve Hay <SteveHay@planit.com>2005-07-08 08:43:07 +0000
commit08bc7695a2f08a85d93cf60f86512524ac215df2 (patch)
treefa4764b87721ec9b5458c60fd4db451208b2db5a /lib/File
parent809e8e66a971d59a948ca995e08b228927d82c66 (diff)
downloadperl-08bc7695a2f08a85d93cf60f86512524ac215df2.tar.gz
Re: [perl #36477] File::Basename basename() bug
Message-ID: <20050707211601.GA3769@windhund.schwern.org> p4raw-id: //depot/perl@25096
Diffstat (limited to 'lib/File')
-rw-r--r--lib/File/Basename.pm10
-rwxr-xr-xlib/File/Basename.t16
2 files changed, 21 insertions, 5 deletions
diff --git a/lib/File/Basename.pm b/lib/File/Basename.pm
index 345edcfe3e..cc6ba5853a 100644
--- a/lib/File/Basename.pm
+++ b/lib/File/Basename.pm
@@ -206,9 +206,13 @@ quoted.
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;
}
diff --git a/lib/File/Basename.t b/lib/File/Basename.t
index 2383744474..84e1a4e92d 100755
--- a/lib/File/Basename.t
+++ b/lib/File/Basename.t
@@ -5,7 +5,7 @@ BEGIN {
@INC = '../lib';
}
-use Test::More tests => 57;
+use Test::More tests => 60;
BEGIN { use_ok 'File::Basename' }
@@ -26,7 +26,6 @@ can_ok( __PACKAGE__, qw( basename fileparse dirname fileparse_set_fstype ) );
is(basename('/arma/virumque.cano'), 'virumque.cano');
is(dirname ('/arma/virumque.cano'), '/arma');
is(dirname('arma/'), '.');
- is(dirname('/'), '/');
}
@@ -131,6 +130,18 @@ can_ok( __PACKAGE__, qw( basename fileparse dirname fileparse_set_fstype ) );
}
+### 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
@@ -150,6 +161,7 @@ can_ok( __PACKAGE__, qw( basename fileparse dirname fileparse_set_fstype ) );
1;
}
+ fileparse_set_fstype 'Unix';
ok tainted(dirname($TAINT.'/perl/lib//'));
ok all_tainted(fileparse($TAINT.'/dir/draft.book7','\.book\d+'));
}