From 6cc7ca361aae2b98c3ab6d7ec2b650c425ffbc4e Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Mon, 1 Oct 2018 09:38:37 +0200 Subject: [PATCH] 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. --- src/option_parser.c | 8 +++----- test/data/test-ini | 1 + test/option_parser.c | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/option_parser.c b/src/option_parser.c index 0cb8354..16fe623 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -203,16 +203,14 @@ int ini_get_bool(const char *section, const char *key, int def) char *clean_value(const char *value) { + size_t len = strlen(value); char *s; - if (value[0] == '"') - s = g_strdup(value + 1); + if (value[0] == '"' && value[len-1] == '"') + s = g_strndup(value + 1, len-2); else s = g_strdup(value); - if (s[strlen(s) - 1] == '"') - s[strlen(s) - 1] = '\0'; - return s; } diff --git a/test/data/test-ini b/test/data/test-ini index 9d2f7cd..0dab3e3 100644 --- a/test/data/test-ini +++ b/test/data/test-ini @@ -22,6 +22,7 @@ simple = A simple string quoted = "A quoted string" quoted_with_quotes = "A string "with quotes"" + unquoted_with_quotes = A" string with quotes" [path] expand_tilde = ~/.path/to/tilde diff --git a/test/option_parser.c b/test/option_parser.c index f2d0960..3b942d8 100644 --- a/test/option_parser.c +++ b/test/option_parser.c @@ -53,6 +53,8 @@ TEST test_ini_get_string(void) free(ptr); ASSERT_STR_EQ("A string \"with quotes\"", (ptr = ini_get_string(string_section, "quoted_with_quotes", ""))); 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"))); free(ptr);