Skip to content

Commit 3651e9e

Browse files
vlmarekpmqs
authored andcommitted
Fix File::GlobMapper wildcard replacement after ordinary letters
The eval-removal change used a single-quoted negative lookbehind containing ${BEGIN_DELIM}. That made the regex treat the characters in the literal string "${BEGIN_DELIM}" as excluded preceding characters, so output patterns such as B#1.out or IMG#1.out did not expand #1. Escaped literal # and * are already protected with HASH_ESC and STAR_ESC before wildcard references are converted to internal markers, so the lookbehind is not needed. Replace exact internal marker sequences directly when generating output filenames. Add a regression test for expanding #1 after an ordinary letter.
1 parent 865b838 commit 3651e9e

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

lib/File/GlobMapper.pm

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ sub _parseOutputGlob
315315
}
316316

317317
my $noPreBS = '(?<!\\\)' ; # no preceding backslash
318-
my $noPreESC = '(?<![${BEGIN_DELIM}])' ; # no preceding backslash
319318

320319
# escape any use of the delimiter symbols
321320
# $string =~ s/(${BEGIN_DELIM}|${END_DELIM}|${BACKSLASH_ESC})/$1$1/g;
@@ -325,7 +324,7 @@ sub _parseOutputGlob
325324
$string =~ s/\\\*/${STAR_ESC}/g;
326325

327326
# Transform "#3" to BEGIN_DELIM 3 END_DELIM
328-
$string =~ s/${noPreESC}#(\d)/${BEGIN_DELIM}${1}${END_DELIM}/g;
327+
$string =~ s/#(\d)/${BEGIN_DELIM}${1}${END_DELIM}/g;
329328

330329
$string =~ s#\*#${BEGIN_DELIM}${END_DELIM}#g;
331330

@@ -351,20 +350,18 @@ sub _getFiles
351350
my $outFile = $inFile ;
352351
my @matches ;
353352

354-
my $noPreESC = '(?<![${BEGIN_DELIM}])' ; # no preceding backslash
355-
356353
if (@matches = ($inFile =~ m/$self->{InputPattern}/ ))
357354
{
358355
$outFile = $self->{OutputPattern};
359356
my $ix = 1;
360357

361358
# get the filename glob
362-
$outFile =~ s/${noPreESC}${BEGIN_DELIM}${END_DELIM}/$inFile/g;
359+
$outFile =~ s/${BEGIN_DELIM}${END_DELIM}/$inFile/g;
363360

364361
# now each of the #1, #2,...
365362
for my $pattern (@matches)
366363
{
367-
$outFile =~ s/${noPreESC}${BEGIN_DELIM}${ix}${END_DELIM}/$pattern/g;
364+
$outFile =~ s/${BEGIN_DELIM}${ix}${END_DELIM}/$pattern/g;
368365

369366
++ $ix;
370367
}

t/globmapper.t

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Perl $]" )
2424
$extra = 1
2525
if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 };
2626

27-
plan tests => 76 + $extra ;
27+
plan tests => 80 + $extra ;
2828

2929
use_ok('File::GlobMapper') ;
3030
}
@@ -340,6 +340,24 @@ Perl $]" )
340340
], " got mapping";
341341
}
342342

343+
{
344+
title "check wildcard references after ordinary letters";
345+
346+
my $tmpDir ;#= 'td';
347+
my $lex = LexDir->new( $tmpDir );
348+
349+
touch map { "$tmpDir/$_.tmp" } qw( abc ) ;
350+
351+
my $map = File::GlobMapper::globmap("$tmpDir/a*.tmp", "$tmpDir/B#1.out");
352+
ok $map, " got map"
353+
or diag $File::GlobMapper::Error ;
354+
355+
is @{ $map }, 1, " returned 1 map";
356+
is_deeply $map,
357+
[ [map { "$tmpDir/$_" } ("abc.tmp", "Bbc.out")],
358+
], " got mapping";
359+
}
360+
343361
# TODO
344362
# test each of the wildcard metacharacters can be mapped to the output filename
345363
#

0 commit comments

Comments
 (0)