user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] search: fix argv handling of quoted phrases
  @ 2021-02-10  9:59  7%   ` Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2021-02-10  9:59 UTC (permalink / raw)
  To: meta

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');

^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-02-08  9:05     [PATCH 00/13] lei approxidate, startup fix, --alert 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  7%   ` [PATCH] search: fix argv handling of quoted phrases Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).