From: Eric Wong <e@80x24.org> To: meta@public-inbox.org Subject: [PATCH] search: fix argv handling of quoted phrases Date: Wed, 10 Feb 2021 08:59:26 -0100 Message-ID: <20210210095926.GA12727@dcvr> (raw) In-Reply-To: <20210208090521.28909-12-e@80x24.org> This fixes both an old bug in "lei q" argv handling and one recent regression introduced with the change to use approxidate. Field prefixes are also handled correctly inside parenthesized statements when the field follows "(" without a separation character. Fixes: fbb7ccabbf54a405 ("lei q: use git approxidate with d:, dt: and rt: ranges") --- lib/PublicInbox/Search.pm | 4 +++- t/search.t | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 76a270bc..b3fd532d 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -330,8 +330,10 @@ sub query_argv_to_string { if (s!\b(d|rt|dt):([[:print:]]+)\z!date_parse_prepare( $to_parse //= [], $1, $2)!sge) { $_; + } elsif (/\s/) { + s/(.*?)\b(\w+:)// ? qq{$1$2"$_"} : qq{"$_"}; } else { - /\s/ ? (s/\A(\w+:)// ? qq{$1"$_"} : qq{"$_}) : $_ + $_ } } @$argv); # git-rev-parse can handle any number of args up to system diff --git a/t/search.t b/t/search.t index 36a8fb30..bcfe91f5 100644 --- a/t/search.t +++ b/t/search.t @@ -536,13 +536,20 @@ $ibx->with_umask(sub { }); SKIP: { + my ($s, $g) = ($ibx->search, $ibx->git); + my $q = $s->query_argv_to_string($g, ["quoted phrase"]); + is($q, q["quoted phrase"], 'quoted phrase'); + $q = $s->query_argv_to_string($g, ['s:pa ce']); + is($q, q[s:"pa ce"], 'space with prefix'); + $q = $s->query_argv_to_string($g, ["\(s:pa ce", "AND", "foo\)"]); + is($q, q[(s:"pa ce" AND foo)], 'space AND foo'); + local $ENV{TZ} = 'UTC'; my $now = strftime('%H:%M:%S', gmtime(time)); if ($now =~ /\A23:(?:59|60)/ || $now =~ /\A00:00:0[01]\z/) { skip 'too close to midnight, time is tricky', 6; } - my ($s, $g) = ($ibx->search, $ibx->git); - my $q = $s->query_argv_to_string($g, [qw(d:20101002 blah)]); + $q = $s->query_argv_to_string($g, [qw(d:20101002 blah)]); is($q, 'd:20101002..20101003 blah', 'YYYYMMDD expanded to range'); $q = $s->query_argv_to_string($g, [qw(d:2010-10-02)]); is($q, 'd:20101002..20101003', 'YYYY-MM-DD expanded to range');
next prev parent reply other threads:[~2021-02-10 9:59 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-08 9:05 [PATCH 00/13] lei approxidate, startup fix, --alert Eric Wong 2021-02-08 9:05 ` [PATCHv2 01/13] lei q: improve remote mboxrd UX + MUA Eric Wong 2021-02-08 9:05 ` [PATCH 02/13] lei_xsearch: quiet Eml warnings from remote mboxrds Eric Wong 2021-02-08 9:05 ` [PATCH 03/13] lei q: SIGWINCH process group with the terminal Eric Wong 2021-02-08 9:05 ` [PATCH 04/13] lei q: support --alert=CMD for early MUA users Eric Wong 2021-02-08 9:05 ` [PATCH 05/13] tests: favor IPv6 Eric Wong 2021-02-08 9:05 ` [PATCH 06/13] ds: improve add_timer usability Eric Wong 2021-02-08 9:05 ` [PATCH 07/13] lei: start_pager: drop COLUMNS default Eric Wong 2021-02-08 9:05 ` [PATCH 08/13] lei: avoid racing on unlink + bind + listen Eric Wong 2021-02-08 9:05 ` [PATCH 09/13] lei: drop BSD::Resource usage Eric Wong 2021-02-08 9:05 ` [PATCH 10/13] git: implement date_parse method Eric Wong 2021-02-08 9:05 ` [PATCH 11/13] lei q: use git approxidate with d:, dt: and rt: ranges Eric Wong 2021-02-10 9:59 ` Eric Wong [this message] 2021-02-08 9:05 ` [PATCH 12/13] search: use one git-rev-parse process for all dates Eric Wong 2021-02-08 9:05 ` [PATCH 13/13] spawnpp: raise exception on E2BIG errors Eric Wong
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://public-inbox.org/README * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210210095926.GA12727@dcvr \ --to=e@80x24.org \ --cc=meta@public-inbox.org \ --subject='Re: [PATCH] search: fix argv handling of quoted phrases' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
user/dev discussion of public-inbox itself This inbox may be cloned and mirrored by anyone: git clone --mirror https://public-inbox.org/meta git clone --mirror http://czquwvybam4bgbro.onion/meta git clone --mirror http://hjrcffqmbrq6wope.onion/meta git clone --mirror http://ou63pmih66umazou.onion/meta # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \ meta@public-inbox.org public-inbox-index meta Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta nntp://news.gmane.io/gmane.mail.public-inbox.general note: .onion URLs require Tor: https://www.torproject.org/ code repositories for project(s) associated with this inbox: https://80x24.org/public-inbox.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git