From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id AHO6BNVBGGLwagAAgWs5BA (envelope-from ) for ; Fri, 25 Feb 2022 03:41:25 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id aMMdAtVBGGJYCAEA9RJhRA (envelope-from ) for ; Fri, 25 Feb 2022 03:41:25 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7C2424657A for ; Fri, 25 Feb 2022 03:41:24 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 903185F6F1; Fri, 25 Feb 2022 02:41:12 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id CD3FA5F6C0 for ; Fri, 25 Feb 2022 02:41:09 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 0BCEE5FC0D; Thu, 24 Feb 2022 21:41:08 -0500 (EST) Received: (nullmailer pid 1026685 invoked by uid 1000); Fri, 25 Feb 2022 02:41:05 -0000 From: David Bremner To: Sean Whitton , notmuch@notmuchmail.org Subject: [PATCH 2/2] lib: do not phrase parse prefixed bracketed subexpressions Date: Thu, 24 Feb 2022 22:41:03 -0400 Message-Id: <20220225024103.1026629-3-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220225024103.1026629-1-david@tethera.net> References: <87y221txsi.fsf@athena.silentflame.com> <20220225024103.1026629-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: ZRXBRI4QVDF3JGDHIHIADVO27LSHPQAT X-Message-ID-Hash: ZRXBRI4QVDF3JGDHIHIADVO27LSHPQAT X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1645756884; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=brJ8g1UAXQpXjtmedO3u9+MQOnoKLDhLdBQqBV+UD48=; b=GNyk72u5bAjEfUZ0VkucrCcIqQMEFmIHilgy47GZJHtSDC7Y+CkO++nPC7AxBx+9WSsfBL ShHeWmz7QiRAm+yX4HTDAnAw770xDc6KqXI8seGzTomuqiYKjxtvCKX+OQwdVvs0Y4Yv6p tTAF/6oY5JecXS+8PeMVeHtsPEos070qwJRDoLQM9OGtstqBHNXR7BP9Ao2Sdu+DnTh3g/ SDmoVrvAfhVHb0EUpCXklhSeM3+OREzhvzJ9iFEtorURUc6RV4PGzgMab/e671heON8F9u ZdOLJXozXbV4RvEanG+VNnaqVuLrjBTrBpDGza+aaoqGKg/7HjxmyhnGT8tYWw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645756884; a=rsa-sha256; cv=none; b=nT1x0N8bps1B4Hi6ApJupWa/mJKz7QomJ+7pmiccdDIU6uuxzYc4D532ucaCPiXGquVpMh B5Lo2xYOJdWZ+jehH6GseB2DSjEceN8qViAdAXPWNt7bfazJkKvj5QawlrTF27X31RLrf1 Jxst+yL2WXMj03dvbxW/eAb6csoRFLgSmpcRTrIwx13yqdF4tIYO9REIuSXocUhqeB222h ta8tQ4EcMh3ZJdIuy8654Zm1T7MLHBW6ILMLSRHrbo2O/jnAIQexEnMCVgYaoVwLlB00HW j6GYgduMArFo4UtF/r+eYaV/gBHgXW4J5XlayfmOWc+f/KPCdyewUcHmrlEnHQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.33 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 7C2424657A X-Spam-Score: -1.33 X-Migadu-Scanner: scn0.migadu.com X-TUID: Jl//O90bIb+i Since Xapian does not preserve quotes when passing the subquery to a field processor, we have to make a guess as to what the user intended. Here the added assumption is that a string surrounded by parens is not intended to be a phrase. --- doc/man7/notmuch-search-terms.rst | 6 ++++-- lib/regexp-fields.cc | 3 ++- test/T650-regexp-query.sh | 13 ++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst index e80cc7d0..f8ad1edb 100644 --- a/doc/man7/notmuch-search-terms.rst +++ b/doc/man7/notmuch-search-terms.rst @@ -275,11 +275,13 @@ the same phrase. - a.list.of.words Both parenthesised lists of terms and quoted phrases are ok with -probabilistic prefixes such as **to:**, **from:**, and **subject:**. In particular +probabilistic prefixes such as **to:**, **from:**, and **subject:**. +For prefixes supporting regex search, the parenthesised list should be +quoted. In particular :: - subject:(pizza free) + subject:"(pizza free)" is equivalent to diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc index 7e9d959c..539915d8 100644 --- a/lib/regexp-fields.cc +++ b/lib/regexp-fields.cc @@ -227,7 +227,8 @@ RegexpFieldProcessor::operator() (const std::string & str) * phrase parsing, when possible */ std::string query_str; - if (*str.rbegin () != '*' || str.find (' ') != std::string::npos) + if ((str.at (0) != '(' || *str.rbegin () != ')') && + (*str.rbegin () != '*' || str.find (' ') != std::string::npos)) query_str = '"' + str + '"'; else query_str = str; diff --git a/test/T650-regexp-query.sh b/test/T650-regexp-query.sh index 4ee6b171..a9844501 100755 --- a/test/T650-regexp-query.sh +++ b/test/T650-regexp-query.sh @@ -66,23 +66,30 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "bracketed subject search (with dquotes)" -test_subtest_known_broken notmuch search subject:notmuch and subject:show > EXPECTED notmuch search 'subject:"(show notmuch)"' > OUTPUT test_expect_equal_file_nonempty EXPECTED OUTPUT test_begin_subtest "bracketed subject search (with dquotes and operator 'or')" -test_subtest_known_broken notmuch search subject:notmuch or subject:show > EXPECTED notmuch search 'subject:"(notmuch or show)"' > OUTPUT test_expect_equal_file_nonempty EXPECTED OUTPUT test_begin_subtest "bracketed subject search (with dquotes and operator 'and')" -test_subtest_known_broken notmuch search subject:notmuch and subject:show > EXPECTED notmuch search 'subject:"(notmuch and show)"' > OUTPUT test_expect_equal_file_nonempty EXPECTED OUTPUT +test_begin_subtest "bracketed subject search (with phrase, operator 'or')" +notmuch search 'subject:"mailing list"' or subject:FreeBSD > EXPECTED +notmuch search 'subject:"(""mailing list"" or FreeBSD)"' > OUTPUT +test_expect_equal_file_nonempty EXPECTED OUTPUT + +test_begin_subtest "bracketed subject search (with phrase, operator 'and')" +notmuch search search 'subject:"notmuch show"' and subject:commands > EXPECTED +notmuch search 'subject:"(""notmuch show"" and commands)"' > OUTPUT +test_expect_equal_file_nonempty EXPECTED OUTPUT + test_begin_subtest "xapian wildcard search for from:" notmuch search --output=messages 'from:cwo*' > OUTPUT test_expect_equal_file cworth.msg-ids OUTPUT -- 2.34.1