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 4Bl8IDFE62EnZwEAgWs5BA (envelope-from ) for ; Sat, 22 Jan 2022 00:39:29 +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 yHsrHTFE62H9bgEAauVa8A (envelope-from ) for ; Sat, 22 Jan 2022 00:39:29 +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 EC37C1C021 for ; Sat, 22 Jan 2022 00:39:28 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6290E5F727; Fri, 21 Jan 2022 23:39:08 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 8AB1B5F712 for ; Fri, 21 Jan 2022 23:39:04 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 0EF865FC75; Fri, 21 Jan 2022 18:39:03 -0500 (EST) Received: (nullmailer pid 1049233 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 6/6] lib: strip trailing '/' from pathnames (sexp queries). Date: Fri, 21 Jan 2022 19:38:53 -0400 Message-Id: <20220121233853.1049166-7-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: KKZTZGQTOACDZ2AI52VO3YLR3DHNPOTC X-Message-ID-Hash: KKZTZGQTOACDZ2AI52VO3YLR3DHNPOTC 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=1642808369; 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=vK5ONstW+8X5tkhw7Zn9DKUtl82Ggtsrc7MTlhBsbN4=; b=J3eSCCnTtPZel5GU2eicBdPUmwLuYTAKa7DeuKfIhcREWEsFzpxZ976ddAsXj0K/2DTBaL gh8AUu5MX/q8aqvKf3L9Uz4pAlJucnbVAazNR/uZoOWwEqEfDz/PzIBuvb3FhbF1aY0jnW XQedPs88x2XMhktiKvB2SGt8xPVy/nyBjkUEQklwfudtFQpvm0RffYMzc4Vuaf1aQtYsn/ dyKv73e+B/HhqxjGy/mydbDqqqzXyZv2yOdd9TMebGZ79/mAZxoaL+uR1jFgCTmKRwNLSa B86O3tdsdusZfLHG2uedXGH7CuTL8pk6YqfUVLky8O8KDbVvjA4drbxoIh8/bQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642808369; a=rsa-sha256; cv=none; b=Uiz4ARw/z5i2YPtMywxUQf8DYueKT6A0BKL9jUsk5hCFoewaTJYLKyndVSCNd0UOM1y+oB EXaKafvnzcpJKK216WTE2t0qGsXpdKuvp3HV6Izd20NgKkPw8MLyATex/ju7TJgjm5bKVA 494uvUB1wQ6FoSgyuKnjke0S4rEdpUSJKKeZFm9LRe0V1n7phSvqGgtGsaB7Uj6oXXQypB cb+UqjrDdJnbC7slwkXvHw2KBNbgiYE8iMlybYOUPjmRwX04liN5UTCme85kxxVyXktVbt Qj7Bf+aMQ1GeoJ+or4YszZ+Qnhs0TPElpzxGnUNLNOtB/vNpbJy8QQxWMqERsw== 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.35 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: EC37C1C021 X-Spam-Score: -1.35 X-Migadu-Scanner: scn1.migadu.com X-TUID: fnk7dKJzb0yg This changes makes the sexp query parser consistent with the infix one in ignoring trailing '/'. Here we do a bit better and ignore any number of trailing '/'. --- lib/parse-sexp.cc | 14 +++++++++++--- test/T081-sexpr-search.sh | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index 06825dc4..08fd7037 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -33,6 +33,7 @@ typedef enum { SEXP_FLAG_DO_EXPAND = 1 << 7, SEXP_FLAG_ORPHAN = 1 << 8, SEXP_FLAG_RANGE = 1 << 9, + SEXP_FLAG_PATHNAME = 1 << 10, } _sexp_flag_t; /* @@ -72,7 +73,8 @@ static _sexp_prefix_t prefixes[] = { "from", Xapian::Query::OP_AND, Xapian::Query::MatchAll, SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND }, { "folder", Xapian::Query::OP_OR, Xapian::Query::MatchNothing, - SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND }, + SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND | + SEXP_FLAG_PATHNAME }, { "id", Xapian::Query::OP_OR, Xapian::Query::MatchNothing, SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX }, { "infix", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll, @@ -94,7 +96,8 @@ static _sexp_prefix_t prefixes[] = { "or", Xapian::Query::OP_OR, Xapian::Query::MatchNothing, SEXP_FLAG_NONE }, { "path", Xapian::Query::OP_OR, Xapian::Query::MatchNothing, - SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX }, + SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | + SEXP_FLAG_PATHNAME }, { "property", Xapian::Query::OP_AND, Xapian::Query::MatchAll, SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND }, { "query", Xapian::Query::OP_INVALID, Xapian::Query::MatchNothing, @@ -545,8 +548,13 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, const _sexp_prefix_t *parent return _sexp_parse_wildcard (notmuch, parent, env, "", output); } + char *atom = sx->val; + + if (parent && parent->flags & SEXP_FLAG_PATHNAME) + strip_trailing (atom, '/'); + if (parent && (parent->flags & SEXP_FLAG_BOOLEAN)) { - output = Xapian::Query (term_prefix + sx->val); + output = Xapian::Query (term_prefix + atom); return NOTMUCH_STATUS_SUCCESS; } diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index ebf2c59f..e2936cd7 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -191,7 +191,6 @@ test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX MAIL_DIR/duplicate/bad/news/msg-XXX" test_begin_subtest "Search by 'folder' with --output=files (trailing /)" -test_subtest_known_broken output=$(notmuch search --output=files --query=sexp '(folder bad/news/)' | notmuch_search_files_sanitize) test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX MAIL_DIR/duplicate/bad/news/msg-XXX" @@ -203,7 +202,6 @@ thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread) thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)" test_begin_subtest "Search by 'folder' (multiple, trailing /)" -test_subtest_known_broken output=$(notmuch search --query=sexp '(folder bad bad/news/ things/bad)' | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread) thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread) @@ -215,7 +213,6 @@ test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX MAIL_DIR/duplicate/bad/news/msg-XXX" test_begin_subtest "Search by 'path' with --output=files (trailing /)" -test_subtest_known_broken output=$(notmuch search --output=files --query=sexp '(path bad/news/)' | notmuch_search_files_sanitize) test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX MAIL_DIR/duplicate/bad/news/msg-XXX" @@ -227,7 +224,6 @@ thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread) thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)" test_begin_subtest "Search by 'path' specification (multiple, trailing /)" -test_subtest_known_broken output=$(notmuch search --query=sexp '(path bad bad/news/ things/bad)' | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread) thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread) -- 2.34.1