]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_external: fix+test handling of escaped braces
authorEric Wong <e@80x24.org>
Wed, 10 Feb 2021 08:38:39 +0000 (07:38 -0100)
committerEric Wong <e@80x24.org>
Wed, 10 Feb 2021 19:21:39 +0000 (19:21 +0000)
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
t/lei_external.t

index 8a51afcb59a17e789be3af65b2e4d85d7250a48d..6cc2e671d9eb4d9b789de6a3310fcf77bbfb1319 100644 (file)
@@ -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;
 }
 
index 0ef6633df0282e84c4cf91dff7c1e349c2b3244c..78f71658529745a99b41d6bc3ef379d2ea49ca90 100644 (file)
@@ -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;