require File::Find;
import File::Find;
}
+
cleanup();
find({wanted => sub { print "ok 1\n" if $_ eq 'access.t'; } },
finddepth({wanted => sub { print "ok 2\n" if $_ eq 'access.t'; } },
File::Spec->curdir);
+
my $case = 2;
my $FastFileTests_OK = 0;
sub cleanup {
if (-d dir_path('for_find')) {
chdir(dir_path('for_find'));
- }
- if (-d dir_path('fa')) {
- unlink file_path('fa', 'fa_ord'),
- file_path('fa', 'fsl'),
- file_path('fa', 'faa', 'faa_ord'),
- file_path('fa', 'fab', 'fab_ord'),
- file_path('fa', 'fab', 'faba', 'faba_ord'),
- file_path('fb', 'fb_ord'),
- file_path('fb', 'fba', 'fba_ord');
- rmdir dir_path('fa', 'faa');
- rmdir dir_path('fa', 'fab', 'faba');
- rmdir dir_path('fa', 'fab');
- rmdir dir_path('fa');
- rmdir dir_path('fb', 'fba');
- rmdir dir_path('fb');
+ if (-d dir_path('fa')) {
+ unlink file_path('fa', 'fa_ord'),
+ file_path('fa', 'fsl'),
+ file_path('fa', 'faa', 'faa_ord'),
+ file_path('fa', 'fab', 'fab_ord'),
+ file_path('fa', 'fab', 'faba', 'faba_ord'),
+ file_path('fb', 'fb_ord'),
+ file_path('fb', 'fba', 'fba_ord');
+ rmdir dir_path('fa', 'faa');
+ rmdir dir_path('fa', 'fab', 'faba');
+ rmdir dir_path('fa', 'fab');
+ rmdir dir_path('fa');
+ rmdir dir_path('fb', 'fba');
+ rmdir dir_path('fb');
+ }
chdir(File::Spec->updir);
rmdir dir_path('for_find');
}
#!./perl -T
-my %Expect_File = (); # what we expect for $_
+my %Expect_File = (); # what we expect for $_
my %Expect_Name = (); # what we expect for $File::Find::name/fullname
my %Expect_Dir = (); # what we expect for $File::Find::dir
my ($cwd, $cwd_untainted);
my $found;
find({wanted => sub { $found = 1 if ($_ eq 'access.t') },
untaint => 1, untaint_pattern => qr|^(.+)$|}, File::Spec->curdir);
-
+
ok($found, 'access.t found');
$found = 0;
-
+
finddepth({wanted => sub { $found = 1 if $_ eq 'access.t'; },
untaint => 1, untaint_pattern => qr|^(.+)$|}, File::Spec->curdir);
-
+
ok($found, 'access.t found again');
my $case = 2;
sub cleanup {
if (-d dir_path('for_find')) {
chdir(dir_path('for_find'));
- }
- if (-d dir_path('fa')) {
- unlink file_path('fa', 'fa_ord'),
- file_path('fa', 'fsl'),
- file_path('fa', 'faa', 'faa_ord'),
- file_path('fa', 'fab', 'fab_ord'),
- file_path('fa', 'fab', 'faba', 'faba_ord'),
- file_path('fb', 'fb_ord'),
- file_path('fb', 'fba', 'fba_ord');
- rmdir dir_path('fa', 'faa');
- rmdir dir_path('fa', 'fab', 'faba');
- rmdir dir_path('fa', 'fab');
- rmdir dir_path('fa');
- rmdir dir_path('fb', 'fba');
- rmdir dir_path('fb');
+ if (-d dir_path('fa')) {
+ unlink file_path('fa', 'fa_ord'),
+ file_path('fa', 'fsl'),
+ file_path('fa', 'faa', 'faa_ord'),
+ file_path('fa', 'fab', 'fab_ord'),
+ file_path('fa', 'fab', 'faba', 'faba_ord'),
+ file_path('fb', 'fb_ord'),
+ file_path('fb', 'fba', 'fba_ord');
+ rmdir dir_path('fa', 'faa');
+ rmdir dir_path('fa', 'fab', 'faba');
+ rmdir dir_path('fa', 'fab');
+ rmdir dir_path('fa');
+ rmdir dir_path('fb', 'fba');
+ rmdir dir_path('fb');
+ }
chdir File::Spec->updir;
rmdir dir_path('for_find');
}
s#\.$## if ($^O eq 'VMS' && $_ ne '.');
ok( $Expect_File{$_}, "Expected and found $File::Find::name" );
if ( $FastFileTests_OK ) {
- delete $Expect_File{ $_}
+ delete $Expect_File{ $_}
unless ( $Expect_Dir{$_} && ! -d _ );
} else {
- delete $Expect_File{$_}
+ delete $Expect_File{$_}
unless ( $Expect_Dir{$_} && ! -d $_ );
}
}
# directory path, independent from the platform it's run on, although
# there are limitations. Don't try to create an absolute path,
# because that may fail on operating systems that have the concept of
-# volume names (e.g. Mac OS). As a special case, you can pass it a "."
+# volume names (e.g. Mac OS). As a special case, you can pass it a "."
# as first argument, to create a directory path like "./fa/dir" on
# operating systems other than Mac OS (actually, Mac OS will ignore
# the ".", if it's the first argument). If there's no second argument,
return '' unless @_;
# ignore first argument; return a relative path
# with leading ":" and with trailing ":"
- return File::Spec->catdir(@_);
+ return File::Spec->catdir(@_);
} else { # other OS
return './' unless @_;
my $path = File::Spec->catdir(@_);
# file_path() concatenates directory names (if any) and a filename to
# form a *relative* file path (the last argument is assumed to be a
# file). It's independent from the platform it's run on, although
-# there are limitations. As a special case, you can pass it a "." as
-# first argument, to create a file path like "./fa/file" on operating
-# systems other than Mac OS (actually, Mac OS will ignore the ".", if
-# it's the first argument). If there's no second argument, this
-# function will return the empty string on Mac OS and the string "./"
+# there are limitations. As a special case, you can pass it a "." as
+# first argument, to create a file path like "./fa/file" on operating
+# systems other than Mac OS (actually, Mac OS will ignore the ".", if
+# it's the first argument). If there's no second argument, this
+# function will return the empty string on Mac OS and the string "./"
# otherwise.
sub file_path {
if ($first_arg eq '.') {
if ($^O eq 'MacOS') {
return '' unless @_;
- # ignore first argument; return a relative path
+ # ignore first argument; return a relative path
# with leading ":", but without trailing ":"
- return File::Spec->catfile(@_);
+ return File::Spec->catfile(@_);
} else { # other OS
return './' unless @_;
my $path = File::Spec->catfile(@_);
- # add leading "./"
- $path = "./$path";
+ # add leading "./"
+ $path = "./$path";
return $path;
}
chdir($cwd_untainted);
-# untaint pattern doesn't match, should die
+# untaint pattern doesn't match, should die
undef $@;
eval {File::Find::find( {wanted => \&simple_wanted, untaint => 1,
chdir($cwd_untainted);
-# untaint pattern doesn't match, should die when we chdir to cwd
+# untaint pattern doesn't match, should die when we chdir to cwd
print "# check untaint_skip (No follow)\n";
undef $@;
print "# $@" if $@;
#$^D = 8;
like( $@, qr|insecure cwd|, 'Bad untaint pattern causes death in cwd (good)' );
-
+
chdir($cwd_untainted);
qr|^(.+)$| }, topdir('fa') );
is( scalar(keys %Expect_File), 0, 'Found all files in symlink test' );
-
-
+
+
# don't untaint at all, should die
undef $@;
like( $@, qr|insecure cwd|, 'Cwd not untainted with bad pattern (good)' );
chdir($cwd_untainted);
-}
-
+}