summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2020-10-04 17:54:15 +0100
committerGitHub <noreply@github.com>2020-10-04 17:54:15 +0100
commit36dc681e8ade941aeee64bb5a8f449a4a5b31924 (patch)
tree0a0044d8dd6c00431d9a9fdb968a803809bfdad8
parent30ba98a11a629a6a4bbe2784a6f1db2698c307ab (diff)
parent6ac18625869063a591828b33453148bf63e679e8 (diff)
downloadlibgit2-36dc681e8ade941aeee64bb5a8f449a4a5b31924.tar.gz
Merge pull request #5629 from csware/config-multiline-parse
Fix config file parsing with multi line values containing quoted parts
-rw-r--r--src/config_parse.c2
-rw-r--r--tests/config/stress.c5
-rw-r--r--tests/resources/config/config1210
3 files changed, 16 insertions, 1 deletions
diff --git a/src/config_parse.c b/src/config_parse.c
index 48ad1164f..ed2c87f6b 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -451,7 +451,7 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var
git_buf_attach(&multi_value, value, 0);
value = NULL;
- if (parse_multiline_variable(reader, &multi_value, quote_count) < 0 ||
+ if (parse_multiline_variable(reader, &multi_value, quote_count % 2) < 0 ||
git_buf_oom(&multi_value)) {
error = -1;
git_buf_dispose(&multi_value);
diff --git a/tests/config/stress.c b/tests/config/stress.c
index 28c3c4ac0..577452e8d 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -59,6 +59,11 @@ void test_config_stress__comments(void)
assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
assert_config_value(config, "some.section.back", "this is \ba phrase");
+ assert_config_value(config, "some.section.dollar", "some $sign");
+ assert_config_value(config, "some.section.multiquotes", "!ls x ls # comment2 $HOME");
+ assert_config_value(config, "some.section.multiquotes2", "!ls x ls \"# comment2 $HOME\"");
+ assert_config_value(config, "some.section.multiquotes3", "hi # ho there are # more quotes");
+ assert_config_value(config, "some.section.quotecomment", "hi # ho there are # more");
git_config_free(config);
}
diff --git a/tests/resources/config/config12 b/tests/resources/config/config12
index 6917880b5..2e92762df 100644
--- a/tests/resources/config/config12
+++ b/tests/resources/config/config12
@@ -11,3 +11,13 @@ and other stuff !@#"
multiline comment # with ;\n special chars \
and other stuff !@#" #^^^
back = "this is \ba phrase"
+ dollar = some $sign
+ multiquotes = !ls "x" \
+ ls "# comment2" \
+ $HOME
+ multiquotes2 = !ls "x" \
+ ls "\"# comment2" \
+ $HOME\"
+ multiquotes3 = hi "# ho" there "are #" more \
+quotes
+ quotecomment = hi "# ho" there "are #" more # and a real comment