From: David Bremner Date: Fri, 24 Mar 2017 22:52:51 +0000 (-0300) Subject: lib: handle empty string in regexp field processors X-Git-Tag: 0.24.1~8 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=cb84f8487833c19ce13edb769fa6421547077725 lib: handle empty string in regexp field processors 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. --- 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)