Commit dfff1b5b by Edward Thomson

Merge pull request #2599 from linquize/config-trailing-spaces

config: Handle multiple spaces that follow a configuration value and precede a comment char
parents 919e7016 a447a7e4
...@@ -1163,7 +1163,7 @@ static int strip_comments(char *line, int in_quotes) ...@@ -1163,7 +1163,7 @@ static int strip_comments(char *line, int in_quotes)
} }
/* skip any space at the end */ /* skip any space at the end */
if (ptr > line && git__isspace(ptr[-1])) { while (ptr > line && git__isspace(ptr[-1])) {
ptr--; ptr--;
} }
ptr[0] = '\0'; ptr[0] = '\0';
......
...@@ -44,12 +44,24 @@ void test_config_stress__comments(void) ...@@ -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_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_git_pass(git_config_get_string(&str, config, "some.section.other"));
cl_assert_equal_s("hello! \" ; ; ; ", str); 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_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_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_git_pass(git_config_get_string(&str, config, "some.section.back"));
cl_assert_equal_s("this is \ba phrase", str); cl_assert_equal_s("this is \ba phrase", str);
......
[some "section"] [some "section"]
test = hi ; comment test = hi ; comment
test2 = hello ; comment
test3 = welcome #comment
other = "hello! \" ; ; ; " ; more test other = "hello! \" ; ; ; " ; more test
other2 = "cool! \" # # # " # more test
multi = "hi, this is a ; \ multi = "hi, this is a ; \
multiline comment # with ;\n special chars \ multiline comment # with ;\n special chars \
and other stuff !@#" and other stuff !@#"
multi2 = "good, this is a ; \
multiline comment # with ;\n special chars \
and other stuff !@#" #^^^
back = "this is \ba phrase" back = "this is \ba phrase"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment