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-ASN: 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 499821F5AE; Tue, 4 May 2021 05:14:20 +0000 (UTC) Date: Tue, 4 May 2021 05:14:19 +0000 From: Eric Wong To: Kyle Meyer Cc: meta@public-inbox.org Subject: Re: [PATCH 4/5] lei ls-mail-sync: fix handling of non-wildcard filters Message-ID: References: <20210504044559.12941-1-kyle@kyleam.com> <20210504044559.12941-5-kyle@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210504044559.12941-5-kyle@kyleam.com> List-Id: Kyle Meyer wrote: > If lei_ls_mail_sync() is given a filter without any wildcards and > --globoff is unspecified, glob2re() will return undef, resulting in > the final regular expression being undefined. Add a fallback value. > --- > > I'm not sure if this is the cleanest approach; repeating > qr/\Q$filter\E/ seems ugly. I considered something closer to what > lei_ls_external() does, but decided against it because it leads to > --globoff with no filter showing no output, which I think is > surprising (even if passing --globoff with no filter doesn't make > any sense). Thanks for bringing this up. My code there was an insomnia-generated disaster :x Mixing a ternary statement with a trailing "if" was just gross. Below is a shorter, less-redundant rewrite based on your fix. > This probably deserves a test, but I'm out of time for tonight. If > the change looks okay, I'm happy to look into adding a test > tomorrow. Yes, but probably no rush. I still need to get mail-sync working... (sidetracked into working on "lei index" :x) ----------8<------------------------ Subject: [PATCH] lei ls-mail-sync: fix handling of non-wildcard filters If lei_ls_mail_sync() is given a filter without any wildcards and --globoff is unspecified, glob2re() will return undef, resulting in the final regular expression being undefined. Always use a fallback value when there's no RE. Based-on-patch-by: Kyle Meyer Link: https://public-inbox.org/meta/20210504044559.12941-5-kyle@kyleam.com/ --- lib/PublicInbox/LeiLsMailSync.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/LeiLsMailSync.pm b/lib/PublicInbox/LeiLsMailSync.pm index 532ea9b5..505c0b3f 100644 --- a/lib/PublicInbox/LeiLsMailSync.pm +++ b/lib/PublicInbox/LeiLsMailSync.pm @@ -12,9 +12,8 @@ sub lei_ls_mail_sync { my $sto = $lei->_lei_store or return; my $lms = $sto->search->lms or return; my $opt = $lei->{opt}; - my $re; - $re = defined($filter) ? qr/\Q$filter\E/ : qr/./ if $opt->{globoff}; - $re //= $lei->glob2re($filter // '*'); + my $re = $opt->{globoff} ? undef : $lei->glob2re($filter // '*'); + $re //= qr/\Q$filter\E/; my @f = $lms->folders; @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f); if ($opt->{'local'} && !$opt->{remote}) {