]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
config: glob2re: fix over-matching /**/foo
authorEric Wong <e@80x24.org>
Tue, 16 Jan 2024 11:52:54 +0000 (11:52 +0000)
committerEric Wong <e@80x24.org>
Wed, 17 Jan 2024 09:37:55 +0000 (09:37 +0000)
Noticed while adding wildcard support to WwwCoderepo...

lib/PublicInbox/Config.pm
t/config.t

index 33c59ec7aaaec3d5cd5c9e923b735e3ad6838e81..b8d3c4855f713bbdae85c3d1efb96f56771bc21e 100644 (file)
@@ -662,7 +662,7 @@ sub squote_maybe ($) {
 }
 
 my %re_map = ( '*' => '[^/]*?', '?' => '[^/]',
-               '/**' => '/.*', '**/' => '.*/', '/**/' => '/.*?',
+               '/**' => '/.*', '**/' => '.*/', '/**/' => '(?:/.*?/|/)',
                '[' => '[', ']' => ']', ',' => ',' );
 
 sub glob2re ($) {
index 975cf836e97c7ed82fffef726bd58fe1a6ec86ae..c41a42d366783a7fa2fc73cb6c6bdeeeb80d21a1 100644 (file)
@@ -296,8 +296,9 @@ is_deeply($glob2re->('\\\\{a,b}'), '\\\\\\\\(a|b)', 'fake escape brace');
 is_deeply($glob2re->('**/foo'), '.*/foo', 'double asterisk start');
 is_deeply($glob2re->('foo/**'), 'foo/.*', 'double asterisk end');
 my $re = $glob2re->('a/**/b');
-is_deeply($re, 'a/.*?b', 'double asterisk middle');
+is_deeply($re, 'a(?:/.*?/|/)b', 'double asterisk middle');
 like($_, qr!$re!, "a/**/b matches $_") for ('a/b', 'a/c/b', 'a/c/a/b');
+unlike($_, qr!$re!, "a/**/b doesn't match $_") for ('a/ab');
 
 {
        my $w = '';