From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E5EBA1F8C2; Wed, 10 Feb 2021 08:38:39 +0000 (UTC) Date: Wed, 10 Feb 2021 07:38:39 -0100 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 7/6] lei_external: fix+test handling of escaped braces Message-ID: <20210210083839.GA12052@dcvr> References: <20210210070749.30391-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210210070749.30391-1-e@80x24.org> List-Id: While '{' and '}' are rare in path names, somebody may still use them or deal with software which does (e.g. GNU arch). --- lib/PublicInbox/LeiExternal.pm | 9 +++++---- t/lei_external.t | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm index 8a51afcb..6cc2e671 100644 --- a/lib/PublicInbox/LeiExternal.pm +++ b/lib/PublicInbox/LeiExternal.pm @@ -58,16 +58,17 @@ sub glob2re { $re_map{$p eq '\\' ? '' : do { if ($1 eq '[') { ++$in_bracket } elsif ($1 eq ']') { --$in_bracket } + elsif ($1 eq ',') { ++$qm } # no change $p = $1; }} // do { $p = $1; ($p eq '-' && $in_bracket) ? $p : (++$qm, "\Q$p") }!sge); # bashism (also supported by curl): {a,b,c} => (a|b|c) - $re =~ s/([^\\]*)\\\{([^,]*?,[^\\]*?)\\\}/ - (my $in_braces = $2) =~ tr!,!|!; - $1."($in_braces)"; - /sge; + $changes += ($re =~ s/([^\\]*)\\\{([^,]*,[^\\]*)\\\}/ + (my $in_braces = $2) =~ tr!,!|!; + $1."($in_braces)"; + /sge); ($changes - $qm) ? $re : undef; } diff --git a/t/lei_external.t b/t/lei_external.t index 0ef6633d..78f71658 100644 --- a/t/lei_external.t +++ b/t/lei_external.t @@ -28,5 +28,7 @@ is_deeply($glob2re->('{a'), undef, 'open left brace'); is_deeply($glob2re->('a}'), undef, 'open right brace'); is_deeply($glob2re->('*.[ch]'), '[^/]*?\\.[ch]', 'suffix glob'); is_deeply($glob2re->('{[a-z],9,}'), '([a-z]|9|)' , 'brace with range'); +is_deeply($glob2re->('\\{a,b\\}'), undef, 'escaped brace'); +is_deeply($glob2re->('\\\\{a,b}'), '\\\\\\\\(a|b)', 'fake escape brace'); done_testing;