From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MN9TCzlE62EOaAEAgWs5BA (envelope-from ) for ; Sat, 22 Jan 2022 00:39:37 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 2AryBzlE62H9bgEAauVa8A (envelope-from ) for ; Sat, 22 Jan 2022 00:39:37 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (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 D08A51BE6D for ; Sat, 22 Jan 2022 00:39:36 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 12FFE5F72F; Fri, 21 Jan 2022 23:39:10 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 368A35F713 for ; Fri, 21 Jan 2022 23:39:07 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 8065E5FC03; Fri, 21 Jan 2022 18:39:06 -0500 (EST) Received: (nullmailer pid 1049227 invoked by uid 1000); Fri, 21 Jan 2022 23:38:58 -0000 From: David Bremner To: David Bremner , David Edmondson , notmuch@notmuchmail.org Subject: [PATCH 4/6] lib: drop trailing slash for path and folder searches (infix) Date: Fri, 21 Jan 2022 19:38:51 -0400 Message-Id: <20220121233853.1049166-5-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220121233853.1049166-1-david@tethera.net> References: <871stgid7j.fsf@tethera.net> <20220121233853.1049166-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: TWOI4ZWMAT7NVTXVQZN744AFQAMLB2BL X-Message-ID-Hash: TWOI4ZWMAT7NVTXVQZN744AFQAMLB2BL 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=1642808376; 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=MY7lNcng9k3q1NLgLDve3mtFkrPyeFgIBlTnutZYN8Q=; b=fQOnpjbRBIFMbqNADYcInrBsQghZNkBEDKk1dWCsEUpFpIIQKIfbOWPUu3YfhX2LDqYbMw Cezy14NYqi+2ler84d57nlSv13pPL1fBG8Gujd++BLFZmW3WyW+47SQCpuwhul+FZTqSUI plakyHzNx2ac6G35v+jXVh2pHxv1tRWIQfHTW0mDy6XvUh/AzkohT0XH1Hgb+AQu9nQWYq rj+cGnGpUE2Ap15rqbcz6vqwIstWOqe1FXPRnvXKB5viQUO2U4/u+0XX1jLXwx1Ep2lrzE B84okiuleCEYn8ruIYJFTO6khP8vO9St8RXyK6uLt2HAiGU3OsYqQGUtkvWU9w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642808376; a=rsa-sha256; cv=none; b=c5iaFdjDytiEPJJm/sGabrLKVuYD/zTP8zvbdjVbYSS0erNVcaNovJSpay3JkhOBg0KkPK FQsu+m5S1UUDlqwBrdSc8rXGHpQxdm0gKkMyzmGolaK3x4SOr4va/xuAvmTSQcBD4GKjSi idWlSmmp35VVk5Up1d/7d9HLN/9DxV/5SruP2y7nSLBj13CCiOizU981ihjyC3WVjrYhpR AJ6YfiK8QfxfSiRjDnlurMuFLWVbsklEbIYwE322jwnbBjBg+B8C6P6ww8kEas14Dd3jau yrpNKiaH8ISMNu/+72nrzUf6pWapNZyII8/t4bF4Ul+92Po6i5ytkm9zPaFU8w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.32 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D08A51BE6D X-Spam-Score: -1.32 X-Migadu-Scanner: scn1.migadu.com X-TUID: RbMG/d88mfGu This resolves an old bug reported by David Edmondson in 2014. The fix is only needed for the "boolean" case, as probabilistic / phrase searching already ignores punctuation. This fix is only for the infix (xapian provided) query parser. [1]: id:cunoasuolcv.fsf@gargravarr.hh.sledj.net --- lib/database-private.h | 1 + lib/prefix.cc | 4 ++-- lib/regexp-fields.cc | 10 +++++++++- test/T100-search-by-folder.sh | 2 -- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index 0c08fa15..657b1aa1 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -165,6 +165,7 @@ typedef enum { NOTMUCH_FIELD_EXTERNAL = 1 << 0, NOTMUCH_FIELD_PROBABILISTIC = 1 << 1, NOTMUCH_FIELD_PROCESSOR = 1 << 2, + NOTMUCH_FIELD_STRIP_TRAILING_SLASH = 1 << 3, } notmuch_field_flag_t; /* diff --git a/lib/prefix.cc b/lib/prefix.cc index 0d92bdd7..857c05b9 100644 --- a/lib/prefix.cc +++ b/lib/prefix.cc @@ -46,7 +46,7 @@ prefix_t prefix_table[] = { { "mid", "Q", NOTMUCH_FIELD_EXTERNAL | NOTMUCH_FIELD_PROCESSOR }, { "path", "P", NOTMUCH_FIELD_EXTERNAL | - NOTMUCH_FIELD_PROCESSOR }, + NOTMUCH_FIELD_PROCESSOR | NOTMUCH_FIELD_STRIP_TRAILING_SLASH }, { "property", "XPROPERTY", NOTMUCH_FIELD_EXTERNAL }, /* * Unconditionally add ':' to reduce potential ambiguity with @@ -55,7 +55,7 @@ prefix_t prefix_table[] = { * discussion. */ { "folder", "XFOLDER:", NOTMUCH_FIELD_EXTERNAL | - NOTMUCH_FIELD_PROCESSOR }, + NOTMUCH_FIELD_PROCESSOR | NOTMUCH_FIELD_STRIP_TRAILING_SLASH }, { "date", NULL, NOTMUCH_FIELD_EXTERNAL | NOTMUCH_FIELD_PROCESSOR }, { "query", NULL, NOTMUCH_FIELD_EXTERNAL | diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc index c6d9d94f..7e9d959c 100644 --- a/lib/regexp-fields.cc +++ b/lib/regexp-fields.cc @@ -235,7 +235,15 @@ RegexpFieldProcessor::operator() (const std::string & str) return parser.parse_query (query_str, NOTMUCH_QUERY_PARSER_FLAGS, term_prefix); } else { /* Boolean prefix */ - std::string term = term_prefix + str; + std::string query_str; + std::string term; + + if (str.length () > 1 && str.at (str.size () - 1) == '/') + query_str = str.substr (0, str.size () - 1); + else + query_str = str; + + term = term_prefix + query_str; return Xapian::Query (term); } } diff --git a/test/T100-search-by-folder.sh b/test/T100-search-by-folder.sh index fbc68266..0123d0b2 100755 --- a/test/T100-search-by-folder.sh +++ b/test/T100-search-by-folder.sh @@ -32,7 +32,6 @@ test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX MAIL_DIR/duplicate/bad/news/msg-XXX" test_begin_subtest "Folder search with --output=files (trailing /)" -test_subtest_known_broken output=$(notmuch search --output=files folder:bad/news/ | notmuch_search_files_sanitize) test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX MAIL_DIR/duplicate/bad/news/msg-XXX" @@ -127,7 +126,6 @@ MAIL_DIR/bar/18:2, MAIL_DIR/cur/51:2," test_begin_subtest "path: search (trailing /)" -test_subtest_known_broken output=$(notmuch search --output=files path:"bar/" | notmuch_search_files_sanitize | sort) # cur/51:2, is a duplicate of bar/18:2, test_expect_equal "$output" "MAIL_DIR/bar/17:2, -- 2.34.1