From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id UIwiKVHxVWHQwwAAgWs5BA (envelope-from ) for ; Thu, 30 Sep 2021 19:18:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CPKuJFHxVWEZWAAAbx9fmQ (envelope-from ) for ; Thu, 30 Sep 2021 17:18:09 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 25B1B2658B for ; Thu, 30 Sep 2021 19:18:09 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id A7EF026DC3; Thu, 30 Sep 2021 13:18:06 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6995F26D7F for ; Thu, 30 Sep 2021 13:18:04 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 614495FD5C; Thu, 30 Sep 2021 13:18:04 -0400 (EDT) Received: (nullmailer pid 4044641 invoked by uid 1000); Thu, 30 Sep 2021 17:18:03 -0000 From: David Bremner To: notmuch@notmuchmail.org, Ciprian Dorin Craciun Cc: David Bremner Subject: [PATCH 2/2] config: ignore leading/trailing spaces in ';'-delimited lists Date: Thu, 30 Sep 2021 14:17:48 -0300 Message-Id: <20210930171748.4044617-2-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210930171748.4044617-1-david@tethera.net> References: <20210930171748.4044617-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 6HIX52BLW2GHBLAI6NE74JBEX5J3QL32 X-Message-ID-Hash: 6HIX52BLW2GHBLAI6NE74JBEX5J3QL32 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; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1633022289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc: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-unsubscribe:list-subscribe:list-post; bh=JmOhzFsL0N+bs0AYLY9nU/ToaSGC22QacfB6/apQ5LU=; b=Kqy0BdiOOf/eYTHNQ6m3IZuU5+0FHOtjZ9GL9wS5efxYPzfApEegE6wHL0QoyAPY9UudG5 bBVLFCenxIgyEYjQ/tuko5/oEF9uEvq/WOwnHpkw3pJaaIqb6dPgxydpcX9OpWrQJqn9aH MpgkOQlyWvQnb1rTqFPeJBPA34aRcTyKOv1EWcAaTmyuaL0IqyeEfvyGT3a6pZhe7fPlcA 3kNoMlOfxs3gomO4dr366AdpvdK37PN2aAUVXfkb6lkv3RVCtTMi5OCnw8eD7UxG1UnWjt 3/3NIMATKpQceZ5XTu+wNCxtiSI5tcmCxx6sEtBTOKAyN+55esqalovSQLlBzg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633022289; a=rsa-sha256; cv=none; b=IZfXemb7aijWIKWkZunp/Ag6o9MtSbuffwuRT19cDBDWtm/ZVaVIAVOrI4NzMSNdJ5+j6s hsLrZqf7YfbXKYyjQTK6t3vADjGUqHhQJ/8M0SQFvLTOVZOnkc4mqIOhHdIOl3S0DCXdjs e2i+EIR4hSGH/V6n7xJDa13ifD9XnTJTTV5nJX1KLZWML11dohGAB+32C8O+kp/qQw5WJk Tbe5lD8q4QcPK6Cq3a8+RKE2lmsy/q4PibqHISJCFu/xPo5/NpBkQ/3+mQEzv1JeATJBye qoRgQKzTHM19AjHDeYHRAKJflctz1KYUrJjw6N5o2jMO5PMV4BJ2BJ8d3BEXiQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.16 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 25B1B2658B X-Spam-Score: -1.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: v5oKt874bca4 In [1] Ciprian observed that it was easy for users to mistakenly introduce leading and trailing space to new.tags when editing a notmuch config file. This commit strips spaces on either side of the ';' delimiter when splitting. In principle it would be possible to support tags (or other config values) with leading or trailing spaces by processing '\s' escapes in the input string. Currently such processing is not done. [1]: id:CA+Tk8fzjPLaEd3vL1f9ebk_bF_RV8PDTLzDupraTkCLCpJAmCg@mail.gmail.com --- test/T050-new.sh | 1 - test/T070-insert.sh | 1 - test/T590-libconfig.sh | 1 - util/string-util.c | 10 ++++++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/T050-new.sh b/test/T050-new.sh index bc20440b..69697c48 100755 --- a/test/T050-new.sh +++ b/test/T050-new.sh @@ -330,7 +330,6 @@ output=$(NOTMUCH_NEW --quiet 2>&1) test_expect_equal "$output" "" test_begin_subtest "leading/trailing whitespace in new.tags is ignored" -test_subtest_known_broken # avoid complications with leading spaces and "notmuch config" sed -i 's/^tags=.*$/tags= fu bar ; ; bar /' notmuch-config add_message diff --git a/test/T070-insert.sh b/test/T070-insert.sh index 9d29c859..ec170b30 100755 --- a/test/T070-insert.sh +++ b/test/T070-insert.sh @@ -235,7 +235,6 @@ test_json_nodes <<<"$output" \ 'new_tags:[0][0][0]["tags"] = ["bar", "foo"]' test_begin_subtest "leading/trailing whitespace in new.tags is ignored" -test_subtest_known_broken # avoid complications with leading spaces and "notmuch config" sed -i 's/^tags=.*$/tags= fu bar ; ; bar /' notmuch-config gen_insert_msg diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index 88647940..768e6576 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -273,7 +273,6 @@ test_expect_equal_file EXPECTED OUTPUT restore_database test_begin_subtest "notmuch_config_get_values (ignore leading/trailing whitespace)" -test_subtest_known_broken cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL% { notmuch_config_values_t *values; diff --git a/util/string-util.c b/util/string-util.c index 9c46a81a..03d7648d 100644 --- a/util/string-util.c +++ b/util/string-util.c @@ -42,13 +42,15 @@ const char * strsplit_len (const char *s, char delim, size_t *len) { bool escaping = false; - size_t count = 0; + size_t count = 0, last_nonspace = 0; - /* Skip initial unescaped delimiters */ - while (*s && *s == delim) + /* Skip initial unescaped delimiters and whitespace */ + while (*s && (*s == delim || isspace (*s))) s++; while (s[count] && (escaping || s[count] != delim)) { + if (! isspace (s[count])) + last_nonspace = count; escaping = (s[count] == '\\'); count++; } @@ -56,7 +58,7 @@ strsplit_len (const char *s, char delim, size_t *len) if (count == 0) return NULL; - *len = count; + *len = last_nonspace + 1; return s; } -- 2.33.0