Allow half quoted values

Previously config lines like

[rule]
script = mail -s "New notif"

were only possible to get written with additional full quotes,
which makes no sense in command line expressions.
This commit is contained in:
Benedikt Heine 2018-10-01 09:38:37 +02:00
parent 357c4309e6
commit 6cc7ca361a
3 changed files with 6 additions and 5 deletions

View File

@ -203,16 +203,14 @@ int ini_get_bool(const char *section, const char *key, int def)
char *clean_value(const char *value) char *clean_value(const char *value)
{ {
size_t len = strlen(value);
char *s; char *s;
if (value[0] == '"') if (value[0] == '"' && value[len-1] == '"')
s = g_strdup(value + 1); s = g_strndup(value + 1, len-2);
else else
s = g_strdup(value); s = g_strdup(value);
if (s[strlen(s) - 1] == '"')
s[strlen(s) - 1] = '\0';
return s; return s;
} }

View File

@ -22,6 +22,7 @@
simple = A simple string simple = A simple string
quoted = "A quoted string" quoted = "A quoted string"
quoted_with_quotes = "A string "with quotes"" quoted_with_quotes = "A string "with quotes""
unquoted_with_quotes = A" string with quotes"
[path] [path]
expand_tilde = ~/.path/to/tilde expand_tilde = ~/.path/to/tilde

View File

@ -53,6 +53,8 @@ TEST test_ini_get_string(void)
free(ptr); free(ptr);
ASSERT_STR_EQ("A string \"with quotes\"", (ptr = ini_get_string(string_section, "quoted_with_quotes", ""))); ASSERT_STR_EQ("A string \"with quotes\"", (ptr = ini_get_string(string_section, "quoted_with_quotes", "")));
free(ptr); free(ptr);
ASSERT_STR_EQ("A\" string with quotes\"", (ptr = ini_get_string(string_section, "unquoted_with_quotes", "")));
free(ptr);
ASSERT_STR_EQ("default value", (ptr = ini_get_string(string_section, "nonexistent", "default value"))); ASSERT_STR_EQ("default value", (ptr = ini_get_string(string_section, "nonexistent", "default value")));
free(ptr); free(ptr);