From 006450b0e2b33ddd5457ead0ca618198843c85a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Marek?= Date: Thu, 11 Jun 2026 15:55:22 +0200 Subject: [PATCH] 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. --- lib/File/GlobMapper.pm | 9 +++------ t/globmapper.t | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/File/GlobMapper.pm b/lib/File/GlobMapper.pm index 6454bc4..2332336 100644 --- a/lib/File/GlobMapper.pm +++ b/lib/File/GlobMapper.pm @@ -315,7 +315,6 @@ sub _parseOutputGlob } my $noPreBS = '(?{InputPattern}/ )) { $outFile = $self->{OutputPattern}; my $ix = 1; # get the filename glob - $outFile =~ s/${noPreESC}${BEGIN_DELIM}${END_DELIM}/$inFile/g; + $outFile =~ s/${BEGIN_DELIM}${END_DELIM}/$inFile/g; # now each of the #1, #2,... for my $pattern (@matches) { - $outFile =~ s/${noPreESC}${BEGIN_DELIM}${ix}${END_DELIM}/$pattern/g; + $outFile =~ s/${BEGIN_DELIM}${ix}${END_DELIM}/$pattern/g; ++ $ix; } diff --git a/t/globmapper.t b/t/globmapper.t index 842562f..824466b 100644 --- a/t/globmapper.t +++ b/t/globmapper.t @@ -24,7 +24,7 @@ Perl $]" ) $extra = 1 if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; - plan tests => 76 + $extra ; + plan tests => 80 + $extra ; use_ok('File::GlobMapper') ; } @@ -340,6 +340,24 @@ Perl $]" ) ], " got mapping"; } +{ + title "check wildcard references after ordinary letters"; + + my $tmpDir ;#= 'td'; + my $lex = LexDir->new( $tmpDir ); + + touch map { "$tmpDir/$_.tmp" } qw( abc ) ; + + my $map = File::GlobMapper::globmap("$tmpDir/a*.tmp", "$tmpDir/B#1.out"); + ok $map, " got map" + or diag $File::GlobMapper::Error ; + + is @{ $map }, 1, " returned 1 map"; + is_deeply $map, + [ [map { "$tmpDir/$_" } ("abc.tmp", "Bbc.out")], + ], " got mapping"; +} + # TODO # test each of the wildcard metacharacters can be mapped to the output filename #