Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for File::chdir #4

Merged
merged 5 commits into from Dec 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/File/chdir.pm
Expand Up @@ -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);
}
Expand All @@ -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) ) {
Expand Down Expand Up @@ -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...
Expand Down
6 changes: 3 additions & 3 deletions t/array.t
Expand Up @@ -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') }

Expand All @@ -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 {
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions t/chdir.t
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions t/delete-array.t
Expand Up @@ -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') }

Expand All @@ -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 {
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions t/newline.t
Expand Up @@ -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;

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions t/var.t
Expand Up @@ -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;

Expand Down