Config parsing confused by continuations that start with quotes (fixes issue #6089) Signed-off-by: Sven Strickroth <email@cs-ware.de>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/src/config_parse.c b/src/config_parse.c
index 3159cbe..e96edc3 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -36,7 +36,7 @@ static int strip_comments(char *line, int in_quotes)
char *ptr;
for (ptr = line; *ptr; ++ptr) {
- if (ptr[0] == '"' && ptr > line && ptr[-1] != '\\')
+ if (ptr[0] == '"' && ((ptr > line && ptr[-1] != '\\') || ptr == line))
quote_count++;
if ((ptr[0] == ';' || ptr[0] == '#') &&
diff --git a/tests/config/read.c b/tests/config/read.c
index 3c96f85..5d23ce4 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -219,6 +219,19 @@ void test_config_read__multiline_multiple_quoted_comment_chars(void)
git_config_free(cfg);
}
+void test_config_read__multiline_multiple_quoted_quote_at_beginning_of_line(void)
+{
+ git_config* cfg;
+ cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config22")));
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m"));
+ cl_assert_equal_s("cmd ;; ;; bar", buf.ptr);
+ git_buf_dispose(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m2"));
+ cl_assert_equal_s("'; ; something '", buf.ptr);
+ git_buf_dispose(&buf);
+ git_config_free(cfg);
+}
+
void test_config_read__header_in_last_line(void)
{
git_config *cfg;
diff --git a/tests/resources/config/config22 b/tests/resources/config/config22
new file mode 100644
index 0000000..2a8e528
--- /dev/null
+++ b/tests/resources/config/config22
@@ -0,0 +1,10 @@
+[alias]
+ m = cmd \
+";;" \
+";;" \
+bar
+ m2 = '\
+";" \
+";" \
+something \
+'