From: Eric Wong Date: Tue, 16 Jan 2024 11:52:54 +0000 (+0000) Subject: config: glob2re: fix over-matching /**/foo X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d99942aa64d7da35847999808f99a068ad25213c;p=thirdparty%2Fpublic-inbox.git config: glob2re: fix over-matching /**/foo Noticed while adding wildcard support to WwwCoderepo... --- diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 33c59ec7a..b8d3c4855 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -662,7 +662,7 @@ sub squote_maybe ($) { } my %re_map = ( '*' => '[^/]*?', '?' => '[^/]', - '/**' => '/.*', '**/' => '.*/', '/**/' => '/.*?', + '/**' => '/.*', '**/' => '.*/', '/**/' => '(?:/.*?/|/)', '[' => '[', ']' => ']', ',' => ',' ); sub glob2re ($) { diff --git a/t/config.t b/t/config.t index 975cf836e..c41a42d36 100644 --- a/t/config.t +++ b/t/config.t @@ -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 = '';