Fixes for File::chdir #4

Merged
merged 5 commits into from Dec 3, 2012
View
@@ -18,7 +18,7 @@ tie @CWD, 'File::chdir::ARRAY' or die "Can't tie \@CWD";
sub _abs_path {
# Otherwise we'll never work under taint mode.
- my($cwd) = Cwd::abs_path =~ /(.*)/s;
+ my($cwd) = Cwd::getcwd =~ /(.*)/s;
# Run through File::Spec, since everything else uses it
return canonpath($cwd);
}
@@ -39,7 +39,8 @@ sub _catpath {
}
sub _chdir {
- my($new_dir) = @_;
+ # Untaint target directory
+ my ($new_dir) = $_[0] =~ /(.*)/s;
local $Carp::CarpLevel = $Carp::CarpLevel + 1;
if ( ! CORE::chdir($new_dir) ) {
@@ -295,7 +296,7 @@ which is much simpler than the equivalent:
sub foo {
use Cwd;
- my $orig_dir = Cwd::abs_path;
+ my $orig_dir = Cwd::getcwd;
chdir('some/other/dir');
...do your work...
View
@@ -3,7 +3,7 @@
use strict;
use Test::More tests => 55;
use File::Spec::Functions qw/canonpath splitdir catdir splitpath catpath/;
-use Cwd qw/getcwd abs_path/;
+use Cwd qw/getcwd/;
BEGIN { use_ok('File::chdir') }
@@ -12,7 +12,7 @@ BEGIN { use_ok('File::chdir') }
#--------------------------------------------------------------------------#-
# _catdir has OS-specific path separators so do the same for getcwd
-sub _getcwd { canonpath( abs_path ) }
+sub _getcwd { canonpath( getcwd ) }
# reassemble
sub _catpath {
@@ -21,7 +21,7 @@ sub _catpath {
}
# get $vol here and use it later
-my ($vol,$cwd) = splitpath(canonpath(abs_path),1);
+my ($vol,$cwd) = splitpath(canonpath(getcwd),1);
# get directory list the way a user would use it -- without empty leading dir
# as returned by splitdir;
View
@@ -3,12 +3,12 @@
use strict;
use Test::More tests => 6;
use File::Spec::Functions qw/canonpath catdir/;
-use Cwd qw/getcwd abs_path/;
+use Cwd qw/getcwd/;
BEGIN { use_ok('File::chdir') }
# _catdir has OS-specific path separators so do the same for getcwd
-sub _getcwd { canonpath( abs_path ) }
+sub _getcwd { canonpath( getcwd ) }
my($cwd) = _getcwd =~ /(.*)/; # detaint otherwise nothing's gonna work
View
@@ -14,7 +14,7 @@ BEGIN {
}
use File::Spec::Functions qw/canonpath splitdir catdir splitpath catpath/;
-use Cwd qw/getcwd abs_path/;
+use Cwd qw/getcwd/;
BEGIN { use_ok('File::chdir') }
@@ -23,7 +23,7 @@ BEGIN { use_ok('File::chdir') }
#--------------------------------------------------------------------------#-
# _catdir has OS-specific path separators so do the same for getcwd
-sub _getcwd { canonpath( abs_path ) }
+sub _getcwd { canonpath( getcwd ) }
# reassemble
sub _catpath {
@@ -32,7 +32,7 @@ sub _catpath {
}
# get $vol here and use it later
-my ($vol,$cwd) = splitpath(canonpath(abs_path),1);
+my ($vol,$cwd) = splitpath(canonpath(getcwd),1);
# get directory list the way a user would use it -- without empty leading dir
# as returned by splitdir;
View
@@ -6,7 +6,7 @@ use warnings;
use Test::More;
use File::chdir;
-use Cwd qw(abs_path);
+use Cwd qw(getcwd);
my $Orig_Cwd = $CWD;
@@ -17,11 +17,11 @@ plan skip_all => "Can't make a directory with a newline in it" unless $Can_mkdir
{
local $CWD = $Test_Dir;
- is $CWD, abs_path;
+ is $CWD, getcwd;
}
is $CWD, $Orig_Cwd;
-is abs_path, $Orig_Cwd;
+is getcwd, $Orig_Cwd;
END {
chdir $Orig_Cwd; # just in case
View
@@ -3,12 +3,12 @@
use strict;
use Test::More tests => 13;
use File::Spec::Functions qw/canonpath catdir/;
-use Cwd qw/getcwd abs_path/;
+use Cwd qw/getcwd/;
BEGIN { use_ok('File::chdir') }
# _catdir has OS-specific path separators so do the same for getcwd
-sub _getcwd { canonpath( abs_path ) }
+sub _getcwd { canonpath( getcwd ) }
my $cwd = _getcwd;