mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
config: ignore leading/trailing spaces in ';'-delimited lists
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
This commit is contained in:
parent
e22bbb124e
commit
bab633d3ac
4 changed files with 6 additions and 7 deletions
|
@ -330,7 +330,6 @@ output=$(NOTMUCH_NEW --quiet 2>&1)
|
||||||
test_expect_equal "$output" ""
|
test_expect_equal "$output" ""
|
||||||
|
|
||||||
test_begin_subtest "leading/trailing whitespace in new.tags is ignored"
|
test_begin_subtest "leading/trailing whitespace in new.tags is ignored"
|
||||||
test_subtest_known_broken
|
|
||||||
# avoid complications with leading spaces and "notmuch config"
|
# avoid complications with leading spaces and "notmuch config"
|
||||||
sed -i 's/^tags=.*$/tags= fu bar ; ; bar /' notmuch-config
|
sed -i 's/^tags=.*$/tags= fu bar ; ; bar /' notmuch-config
|
||||||
add_message
|
add_message
|
||||||
|
|
|
@ -235,7 +235,6 @@ test_json_nodes <<<"$output" \
|
||||||
'new_tags:[0][0][0]["tags"] = ["bar", "foo"]'
|
'new_tags:[0][0][0]["tags"] = ["bar", "foo"]'
|
||||||
|
|
||||||
test_begin_subtest "leading/trailing whitespace in new.tags is ignored"
|
test_begin_subtest "leading/trailing whitespace in new.tags is ignored"
|
||||||
test_subtest_known_broken
|
|
||||||
# avoid complications with leading spaces and "notmuch config"
|
# avoid complications with leading spaces and "notmuch config"
|
||||||
sed -i 's/^tags=.*$/tags= fu bar ; ; bar /' notmuch-config
|
sed -i 's/^tags=.*$/tags= fu bar ; ; bar /' notmuch-config
|
||||||
gen_insert_msg
|
gen_insert_msg
|
||||||
|
|
|
@ -273,7 +273,6 @@ test_expect_equal_file EXPECTED OUTPUT
|
||||||
restore_database
|
restore_database
|
||||||
|
|
||||||
test_begin_subtest "notmuch_config_get_values (ignore leading/trailing whitespace)"
|
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%
|
cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${NOTMUCH_CONFIG} %NULL%
|
||||||
{
|
{
|
||||||
notmuch_config_values_t *values;
|
notmuch_config_values_t *values;
|
||||||
|
|
|
@ -42,13 +42,15 @@ const char *
|
||||||
strsplit_len (const char *s, char delim, size_t *len)
|
strsplit_len (const char *s, char delim, size_t *len)
|
||||||
{
|
{
|
||||||
bool escaping = false;
|
bool escaping = false;
|
||||||
size_t count = 0;
|
size_t count = 0, last_nonspace = 0;
|
||||||
|
|
||||||
/* Skip initial unescaped delimiters */
|
/* Skip initial unescaped delimiters and whitespace */
|
||||||
while (*s && *s == delim)
|
while (*s && (*s == delim || isspace (*s)))
|
||||||
s++;
|
s++;
|
||||||
|
|
||||||
while (s[count] && (escaping || s[count] != delim)) {
|
while (s[count] && (escaping || s[count] != delim)) {
|
||||||
|
if (! isspace (s[count]))
|
||||||
|
last_nonspace = count;
|
||||||
escaping = (s[count] == '\\');
|
escaping = (s[count] == '\\');
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,7 @@ strsplit_len (const char *s, char delim, size_t *len)
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*len = count;
|
*len = last_nonspace + 1;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue