From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id DABD56DE16F1 for ; Fri, 24 Mar 2017 15:53:03 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lgxOt6Y-rYSx for ; Fri, 24 Mar 2017 15:53:02 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 87C636DE16DD for ; Fri, 24 Mar 2017 15:53:01 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1crY49-0004kC-DM; Fri, 24 Mar 2017 18:52:17 -0400 Received: (nullmailer pid 21971 invoked by uid 1000); Fri, 24 Mar 2017 22:52:59 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/2] lib: handle empty string in regexp field processors Date: Fri, 24 Mar 2017 19:52:51 -0300 Message-Id: <20170324225251.21107-3-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170324225251.21107-1-david@tethera.net> References: <20170324225251.21107-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Mar 2017 22:53:04 -0000 The non-field processor behaviour is is convert the corresponding queries into a search for the unprefixed terms. This yields pretty surprising results so I decided to generate a query that would match the terms (i.e. none with that prefix) generated for an empty header. --- lib/regexp-fields.cc | 5 +++++ test/T650-regexp-query.sh | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc index 9dcf9732..1651677c 100644 --- a/lib/regexp-fields.cc +++ b/lib/regexp-fields.cc @@ -148,6 +148,11 @@ RegexpFieldProcessor::RegexpFieldProcessor (std::string prefix, Xapian::QueryPar Xapian::Query RegexpFieldProcessor::operator() (const std::string & str) { + if (str.size () == 0) + return Xapian::Query(Xapian::Query::OP_AND_NOT, + Xapian::Query::MatchAll, + Xapian::Query (Xapian::Query::OP_WILDCARD, term_prefix)); + if (str.at (0) == '/') { if (str.at (str.size () - 1) == '/'){ RegexpPostingSource *postings = new RegexpPostingSource (slot, str.substr(1,str.size () - 2)); diff --git a/test/T650-regexp-query.sh b/test/T650-regexp-query.sh index f2ae1387..9599c104 100755 --- a/test/T650-regexp-query.sh +++ b/test/T650-regexp-query.sh @@ -16,7 +16,6 @@ add_message '[from]="-" [subject]="empty from"' add_message '[subject]="-"' test_begin_subtest "null from: search" -test_subtest_known_broken notmuch search 'from:""' | notmuch_search_sanitize > OUTPUT cat < EXPECTED thread:XXX 2001-01-05 [1/1] -; empty from (inbox unread) @@ -24,7 +23,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "null subject: search" -test_subtest_known_broken notmuch search 'subject:""' | notmuch_search_sanitize > OUTPUT cat < EXPECTED thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; - (inbox unread) -- 2.11.0