From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org,
Ciprian Dorin Craciun <ciprian.craciun@gmail.com>
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 2/2] config: ignore leading/trailing spaces in ';'-delimited lists
Date: Thu, 30 Sep 2021 14:17:48 -0300 [thread overview]
Message-ID: <20210930171748.4044617-2-david@tethera.net> (raw)
In-Reply-To: <20210930171748.4044617-1-david@tethera.net>
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
next prev parent reply other threads:[~2021-09-30 17:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 10:36 Strip spaces in `tags` in `~/.notmuch-config` (and other fields) Ciprian Dorin Craciun
2020-04-24 11:12 ` David Bremner
2021-09-30 17:17 ` David Bremner
2021-09-30 17:17 ` [PATCH 1/2] test: known broken tests for leading/trailing ws in config David Bremner
2021-09-30 17:17 ` David Bremner [this message]
2021-09-30 18:28 ` [PATCH 1/2] test: known broken tests for escape characters in config files David Bremner
2021-09-30 18:28 ` [PATCH 2/2] lib/config: use g_key_file_get_string to read config values David Bremner
2021-09-30 18:59 ` [PATCH v2] " David Bremner
2021-12-04 16:31 ` [PATCH 1/2] test: known broken tests for leading/trailing ws in config David Bremner
2021-12-05 12:41 ` Strip spaces in `tags` in `~/.notmuch-config` (and other fields) David Bremner
2021-12-13 9:09 ` Ciprian Craciun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210930171748.4044617-2-david@tethera.net \
--to=david@tethera.net \
--cc=ciprian.craciun@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).