This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [perl #41421] glob() produces spurious results with brackets in braces
authorSlaven Rezic <slaven@rezic.de>
Fri, 2 Feb 2007 23:08:28 +0000 (00:08 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 2 Feb 2007 23:35:22 +0000 (23:35 +0000)
Message-ID: <87r6t81acj.fsf@biokovo.herceg.de>
Date: 02 Feb 2007 23:08:28 +0100

p4raw-id: //depot/perl@30103

ext/File/Glob/bsd_glob.c
ext/File/Glob/t/basic.t

index 4d1e7f0..c6fce1e 100644 (file)
@@ -431,7 +431,7 @@ globexp2(const Char *ptr, const Char *pattern,
 {
        int     i;
        Char   *lm, *ls;
-       const Char *pe, *pm, *pl;
+       const Char *pe, *pm, *pm1, *pl;
        Char    patbuf[MAXPATHLEN];
 
        /* copy part up to the brace */
@@ -471,14 +471,14 @@ globexp2(const Char *ptr, const Char *pattern,
                switch (*pm) {
                case BG_LBRACKET:
                        /* Ignore everything between [] */
-                       for (pl = pm++; *pm != BG_RBRACKET && *pm != BG_EOS; pm++)
+                       for (pm1 = pm++; *pm != BG_RBRACKET && *pm != BG_EOS; pm++)
                                ;
                        if (*pm == BG_EOS) {
                                /*
                                 * We could not find a matching BG_RBRACKET.
                                 * Ignore and just look for BG_RBRACE
                                 */
-                               pm = pl;
+                               pm = pm1;
                        }
                        break;
 
index fc168b8..cee453c 100755 (executable)
@@ -13,7 +13,7 @@ BEGIN {
         print "1..0\n";
         exit 0;
     }
-    print "1..12\n";
+    print "1..13\n";
 }
 END {
     print "not ok 1\n" unless $loaded;
@@ -187,3 +187,26 @@ rmdir "pteerslo";
 # this can panic if PL_glob_index gets passed as flags to bsd_glob
 <*>; <*>;
 print "ok 12\n";
+
+{
+    use File::Temp qw(tempdir);
+    use File::Spec qw();
+
+    my($dir) = tempdir(CLEANUP => 1)
+       or die "Could not create temporary directory";
+    for my $file (qw(a_dej a_ghj a_qej)) {
+       open my $fh, ">", File::Spec->catfile($dir, $file)
+           or die "Could not create file $dir/$file: $!";
+       close $fh;
+    }
+    my $cwd = Cwd::cwd();
+    chdir $dir
+       or die "Could not chdir to $dir: $!";
+    my(@glob_files) = glob("a*{d[e]}j");
+    if (!(@glob_files == 1 && "@glob_files" eq "a_dej")) {
+       print "not ";
+    }
+    print "ok 13\n";
+    chdir $cwd
+       or die "Could not chdir back to $cwd: $!";
+}