From 0a64164700d3867855a0a7f6d168fb41eb704bf0 Mon Sep 17 00:00:00 2001 From: Linquize Date: Sat, 4 Oct 2014 23:27:06 +0800 Subject: [PATCH 1/2] config: Fix multiple trailing spaces before comments not completely trimmed --- src/config_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'; From a447a7e40b03d1c8ecb49ab0ef015eb4c0fd2b6e Mon Sep 17 00:00:00 2001 From: Linquize Date: Sat, 4 Oct 2014 23:28:40 +0800 Subject: [PATCH 2/2] config: Add test cases that have trailing spaces before comment chars --- tests/config/stress.c | 12 ++++++++++++ tests/resources/config/config12 | Bin 221 -> 440 bytes 2 files changed, 12 insertions(+) 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 b57a81b08a3fa00f9df494ecc29f95145117a72e..6917880b5c94e5d2d0db23cc7d9eb3c7809fa508 100644 GIT binary patch delta 122 zcmcc1xPy6up>auSafy+FtwKg>PENi85LhcD=jZ08=9O@PcnS(21;#)H<*7M9iBtsz z<%!DHviT($sYM`tO3C^8If@D~N(#zgs032rTf&!Hnp2VqR*;^bpE5BskPRpi7Z*2i GmofmUA0vVQ delta 16 YcmdnNe3x;8;lv`{iD#21&ta4S06M`2m;e9(