From: Slaven Rezic Date: Fri, 2 Feb 2007 23:08:28 +0000 (+0100) Subject: Re: [perl #41421] glob() produces spurious results with brackets in braces X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=77348331ba668328554e7a9d261f69ef327189e7;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #41421] glob() produces spurious results with brackets in braces Message-ID: <87r6t81acj.fsf@biokovo.herceg.de> Date: 02 Feb 2007 23:08:28 +0100 p4raw-id: //depot/perl@30103 --- diff --git a/ext/File/Glob/bsd_glob.c b/ext/File/Glob/bsd_glob.c index 4d1e7f0..c6fce1e 100644 --- a/ext/File/Glob/bsd_glob.c +++ b/ext/File/Glob/bsd_glob.c @@ -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; diff --git a/ext/File/Glob/t/basic.t b/ext/File/Glob/t/basic.t index fc168b8..cee453c 100755 --- a/ext/File/Glob/t/basic.t +++ b/ext/File/Glob/t/basic.t @@ -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: $!"; +}