Skip to content

Commit 36dc681

Browse files
authored
Merge pull request libgit2#5629 from csware/config-multiline-parse
Fix config file parsing with multi line values containing quoted parts
2 parents 30ba98a + 6ac1862 commit 36dc681

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/config_parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var
451451
git_buf_attach(&multi_value, value, 0);
452452
value = NULL;
453453

454-
if (parse_multiline_variable(reader, &multi_value, quote_count) < 0 ||
454+
if (parse_multiline_variable(reader, &multi_value, quote_count % 2) < 0 ||
455455
git_buf_oom(&multi_value)) {
456456
error = -1;
457457
git_buf_dispose(&multi_value);

tests/config/stress.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ void test_config_stress__comments(void)
5959
assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
6060
assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
6161
assert_config_value(config, "some.section.back", "this is \ba phrase");
62+
assert_config_value(config, "some.section.dollar", "some $sign");
63+
assert_config_value(config, "some.section.multiquotes", "!ls x ls # comment2 $HOME");
64+
assert_config_value(config, "some.section.multiquotes2", "!ls x ls \"# comment2 $HOME\"");
65+
assert_config_value(config, "some.section.multiquotes3", "hi # ho there are # more quotes");
66+
assert_config_value(config, "some.section.quotecomment", "hi # ho there are # more");
6267

6368
git_config_free(config);
6469
}

tests/resources/config/config12

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ and other stuff !@#"
1111
multiline comment # with ;\n special chars \
1212
and other stuff !@#" #^^^
1313
back = "this is \ba phrase"
14+
dollar = some $sign
15+
multiquotes = !ls "x" \
16+
ls "# comment2" \
17+
$HOME
18+
multiquotes2 = !ls "x" \
19+
ls "\"# comment2" \
20+
$HOME\"
21+
multiquotes3 = hi "# ho" there "are #" more \
22+
quotes
23+
quotecomment = hi "# ho" there "are #" more # and a real comment

0 commit comments

Comments
 (0)