diff --git a/src/config_file.c b/src/config_file.c index 7106f18db..8f55c42f3 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1163,7 +1163,7 @@ static int strip_comments(char *line, int in_quotes) } /* skip any space at the end */ - if (ptr > line && git__isspace(ptr[-1])) { + while (ptr > line && git__isspace(ptr[-1])) { ptr--; } ptr[0] = '\0'; diff --git a/tests/config/stress.c b/tests/config/stress.c index 488915e79..e8e9d2b61 100644 --- a/tests/config/stress.c +++ b/tests/config/stress.c @@ -44,12 +44,24 @@ void test_config_stress__comments(void) cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12"))); + cl_git_pass(git_config_get_string(&str, config, "some.section.test2")); + cl_assert_equal_s("hello", str); + + cl_git_pass(git_config_get_string(&str, config, "some.section.test3")); + cl_assert_equal_s("welcome", str); + cl_git_pass(git_config_get_string(&str, config, "some.section.other")); cl_assert_equal_s("hello! \" ; ; ; ", str); + cl_git_pass(git_config_get_string(&str, config, "some.section.other2")); + cl_assert_equal_s("cool! \" # # # ", str); + cl_git_pass(git_config_get_string(&str, config, "some.section.multi")); cl_assert_equal_s("hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str); + cl_git_pass(git_config_get_string(&str, config, "some.section.multi2")); + cl_assert_equal_s("good, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str); + cl_git_pass(git_config_get_string(&str, config, "some.section.back")); cl_assert_equal_s("this is \ba phrase", str); diff --git a/tests/resources/config/config12 b/tests/resources/config/config12 index b57a81b08..6917880b5 100644 Binary files a/tests/resources/config/config12 and b/tests/resources/config/config12 differ