Giter Club home page Giter Club logo

file-globstar's People

Contributors

gflohr avatar manwar avatar rivy avatar sole6 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

manwar rivy sole6

file-globstar's Issues

BUG: globstar passing undef as a flag to bsd_glob

If I invoke globstar('path/to/dir/**/*.txt') without any glob flags, the result fails because globstar is passing $flags:

    # Bad. Returns 0 files
    my @files = bsd_glob('pat/to/dir/subdir/*.txt', undef)

    # Good. Returns files.=
    my @files = bsd_glob('pat/to/dir/subdir/*.txt');

At least on my build of perl (5.34.1 in Debian Linux), bsd_glob() will fail to find any files if it is called with an undef file.

I was able to fix it with this diff:

diff --git a/lib/File/Globstar.pm b/lib/File/Globstar.pm
index ba4108caf4..aaa77fe9fd 100644
--- a/perlmod/CPAN/perl5.34.1/lib/perl5/File/Globstar.pm
+++ b/perlmod/CPAN/perl5.34.1/lib/perl5/File/Globstar.pm
@@ -120,7 +120,7 @@ sub _globstar($$;$) {
             $current .= '/';
 
             # Expand until here.
-            my @directories = bsd_glob $current, $flags;
+            my @directories = bsd_glob($current, (defined $flags ? $flags : ()));
 
             # And search in every subdirectory;
             my %found_dirs;
@@ -150,7 +150,7 @@ sub _globstar($$;$) {
             return keys %found_files;
         } elsif ('**' eq $pattern) {
             my %found_files;
-            foreach my $directory (bsd_glob $current, $flags) {
+            foreach my $directory (bsd_glob($current, (defined $flags ? $flags : ()))) {
                 $found_files{$directory . '/'} = 1;
                 foreach my $file (_find_all $directory) {
                     $found_files{$file} = 1;
@@ -163,7 +163,7 @@ sub _globstar($$;$) {
     }
 
     # Pattern without globstar.  Just return the normal expansion.
-    return bsd_glob $current, $flags;
+    return bsd_glob($current, (defined $flags ? $flags : ()));
 }
 
 sub globstar {

Bug: globstar fails on windows with directories containing dot

On windows, if you have files named:

  • dir_1/file1.txt
  • dir.2/file2.txt

then globstar('**/*.txt') will find dir_1/file1.txt but will not find dir.2/file2.txt. This is because ultimately _globstar will call bsd_glob('dir\\.2/*.txt') which will not match anything.

You can fix this by exempting . from the hand-rolled quotemeta() embedded in _globstar:

-    # This is a quotemeta() that does not escape the slash and the
-    # colon.  Escaped slashes confuse bsd_glob() and escaping colons
+    # This is a quotemeta() that does not escape the slash, the
+    # colon, or period.  Escaped slashes confuse bsd_glob() and escaping colons
     # may make a full port to Windows harder.
-    $current =~ s{([\x00-\x2e\x3b-\x40\x5b-\x5e\x60\x7b-\x7f])}{\\$1}g;
+    $current =~ s{([\x00-\x2d\x3b-\x40\x5b-\x5e\x60\x7b-\x7f])}{\\$1}g;
     if ($directory ne '' && '/' ne substr $directory, -1, 1) {
         $current .= '/';
     }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.