Skip to content

Commit 433edb5

Browse files
committed
Config parsing confused by continuations that start with quotes
(fixes issue libgit2#6089) Signed-off-by: Sven Strickroth <email@cs-ware.de>
1 parent f9c4dc1 commit 433edb5

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/config_parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int strip_comments(char *line, int in_quotes)
3636
char *ptr;
3737

3838
for (ptr = line; *ptr; ++ptr) {
39-
if (ptr[0] == '"' && ptr > line && ptr[-1] != '\\')
39+
if (ptr[0] == '"' && ((ptr > line && ptr[-1] != '\\') || ptr == line))
4040
quote_count++;
4141

4242
if ((ptr[0] == ';' || ptr[0] == '#') &&

tests/config/read.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ void test_config_read__multiline_multiple_quoted_comment_chars(void)
219219
git_config_free(cfg);
220220
}
221221

222+
void test_config_read__multiline_multiple_quoted_quote_at_beginning_of_line(void)
223+
{
224+
git_config* cfg;
225+
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config22")));
226+
cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m"));
227+
cl_assert_equal_s("cmd ;; ;; bar", buf.ptr);
228+
git_buf_dispose(&buf);
229+
cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m2"));
230+
cl_assert_equal_s("'; ; something '", buf.ptr);
231+
git_buf_dispose(&buf);
232+
git_config_free(cfg);
233+
}
234+
222235
void test_config_read__header_in_last_line(void)
223236
{
224237
git_config *cfg;

tests/resources/config/config22

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[alias]
2+
m = cmd \
3+
";;" \
4+
";;" \
5+
bar
6+
m2 = '\
7+
";" \
8+
";" \
9+
something \
10+
'

0 commit comments

Comments
 (0)