From: Michael G. Schwern Date: Thu, 7 Jul 2005 14:16:01 +0000 (-0700) Subject: Re: [perl #36477] File::Basename basename() bug X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=08bc7695a2f08a85d93cf60f86512524ac215df2;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #36477] File::Basename basename() bug Message-ID: <20050707211601.GA3769@windhund.schwern.org> p4raw-id: //depot/perl@25096 --- diff --git a/lib/File/Basename.pm b/lib/File/Basename.pm index 345edcf..cc6ba58 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 2383744..84e1a4e 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+')); }