Commits

Anonymous committed 0701b5f

Now correctly handling files whose filenames and directories are false in Perl.

Comments (0)

Files changed (3)

-
+0.1.3
     - Refactoring: converted _movenext() from pseudo-conditionals
     to polymorphism by making it a method of ->_current().
     - Refactoring: extracted the _next_traverse_to() method.
+    - Bug fix (with possible correctness/SECURITY implications):
+        - now correctly handling files and directories whose filenames
+        are false in Perl - most notable "0".
 
 0.1.2 - Sun Oct 26 12:57:55 IST 2008
     - Corrected the README.

lib/File/Find/Object.pm

 {
     my ($self, $top) = @_;
 
-    # TODO :
-    # Implement traversal to files with the filenames of exactly "0".
-    if ($self->_curr_file(
+    if (defined($self->_curr_file(
             $top->_father($self)->_next_traverse_to()
-       ))
+       )))
     {
         $self->_reset_actions();
         return 1;
 sub _check_process_current {
     my $self = shift;
 
-    return ($self->_current->_curr_file() && $self->_filter_wrapper());
+    return (defined($self->_current->_curr_file()) && $self->_filter_wrapper());
 }
 
 # Return true if there is somthing next
 use strict;
 use warnings;
 
-use Test::More tests => 38;
+use Test::More tests => 39;
 
 BEGIN
 {
 
     rmtree($t->get_path("./t/sample-data/traverse-1"))
 }
+
+{
+    my $tree =
+    {
+        'name' => "traverse-1/",
+        'subs' =>
+        [
+            {
+                'name' => "0/",
+            },
+            {
+                'name' => "foo/",
+                'subs' =>
+                [
+                    {
+                        'name' => "0",
+                        'contents' => "Zero file",
+                    },
+                    {
+                        'name' => "1",
+                        'contents' => "One file",
+                    },
+                    {
+                        'name' => "2",
+                        'contents' => "Two file",
+                    },
+                    
+
+                ],
+            },
+        ],
+    };
+
+    my $t = File::Find::Object::TreeCreate->new();
+    $t->create_tree("./t/sample-data/", $tree);
+
+    my $ff =
+        File::Find::Object->new(
+            {},
+            $t->get_path("./t/sample-data/traverse-1")
+        );
+
+    my @results;
+    for my $i (1 .. 7)
+    {
+        push @results, $ff->next();
+    }
+
+    # TEST
+    is_deeply(
+        \@results,
+        [(map { $t->get_path("t/sample-data/traverse-1/$_") }
+            sort {$a cmp $b }
+            ("", qw(
+                0
+                foo
+                foo/0
+                foo/1
+                foo/2
+            ))),
+         undef
+        ],
+        "Checking that files named '0' are correctly scanned",
+    );
+
+    rmtree($t->get_path("./t/sample-data/traverse-1"));
+}