]> git.notmuchmail.org Git - notmuch/commitdiff
config: ignore leading/trailing spaces in ';'-delimited lists
authorDavid Bremner <david@tethera.net>
Thu, 30 Sep 2021 17:17:48 +0000 (14:17 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 4 Dec 2021 16:16:12 +0000 (12:16 -0400)
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
test/T070-insert.sh
test/T590-libconfig.sh
util/string-util.c

index bc20440b8212e34600bca39c7732e23c79040828..69697c48248502866a66853f7348b4e17727e5b8 100755 (executable)
@@ -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
index 9d29c859fc5df3b9f5e32ac66fa0e5023c47a1ee..ec170b30a42e18ce8fbc6866ee06bbbec7dc302b 100755 (executable)
@@ -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
index 912aaa1fa5802d9f3a60cb8a3d16e701d2de1f35..6c426ae8f6365a578c9f892675aa13c83fb2f6a7 100755 (executable)
@@ -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;
index 9c46a81a58e20030b586953e577efd777ef2af17..03d7648d329a2e7b3667a894b558e93d440d1a6a 100644 (file)
@@ -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;
 }