lib/PublicInbox/LeiExternal.pm | 4 ++--
lib/PublicInbox/LeiLsExternal.pm | 1 +
lib/PublicInbox/LeiLsMailSync.pm | 7 +++++--
diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index 30bb1a4579c74d8245d1eec7b66b9687bd526e71..a6562e7f08f6d36a9b27f8c412cafbef5696aae2 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
# *-external commands of lei
@@ -88,7 +88,7 @@ my @m;
my @cur = externals_each($self);
my $do_glob = !$self->{opt}->{globoff}; # glob by default
if ($do_glob && (my $re = glob2re($loc))) {
- @m = grep(m!$re!, @cur);
+ @m = grep(m!$re/?\z!, @cur);
return @m if scalar(@m);
} elsif (index($loc, '/') < 0) { # exact basename match:
@m = grep(m!/\Q$loc\E/?\z!, @cur);
diff --git a/lib/PublicInbox/LeiLsExternal.pm b/lib/PublicInbox/LeiLsExternal.pm
index dd2eb2e7d16e60f0c3ae935eaf804ea83f52ecd2..e624cbd48af16296a6f0f056224720149f8944cb 100644
--- a/lib/PublicInbox/LeiLsExternal.pm
+++ b/lib/PublicInbox/LeiLsExternal.pm
@@ -13,6 +13,7 @@ my $do_glob = !$lei->{opt}->{globoff}; # glob by default
my ($OFS, $ORS) = $lei->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n");
$filter //= '*';
my $re = $do_glob ? $lei->glob2re($filter) : undef;
+ $re .= '/?\\z' if defined $re;
$re //= index($filter, '/') < 0 ?
qr!/\Q$filter\E/?\z! : # exact basename match
qr/\Q$filter\E/; # grep -F semantics
diff --git a/lib/PublicInbox/LeiLsMailSync.pm b/lib/PublicInbox/LeiLsMailSync.pm
index 2b167b1d68ff34edb2d071174ed71421416cfb17..8da0c284799a81418aff2d1ef0fd58513728bffb 100644
--- a/lib/PublicInbox/LeiLsMailSync.pm
+++ b/lib/PublicInbox/LeiLsMailSync.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
# front-end for the "lei ls-mail-sync" sub-command
@@ -12,7 +12,10 @@ my ($lei, $filter) = @_;
my $lms = $lei->lms or return;
my $opt = $lei->{opt};
my $re = $opt->{globoff} ? undef : $lei->glob2re($filter // '*');
- $re //= qr/\Q$filter\E/;
+ $re .= '/?\\z' if defined $re;
+ $re //= index($filter, '/') < 0 ?
+ qr!/\Q$filter\E/?\z! : # exact basename match
+ qr/\Q$filter\E/; # grep -F semantics
my @f = $lms->folders;
@f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
if ($opt->{'local'} && !$opt->{remote}) {