config_parse: handle empty lines with CRLF Currently, the configuration parser will fail reading empty lines with just an CRLF-style line ending. Special-case the '\r' character in order to handle it the same as Unix-style line endings. Add tests to spot this regression in the future.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/src/config_parse.c b/src/config_parse.c
index 2b9669c..981f968 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -495,6 +495,7 @@ int git_config_parse(
break;
case '\n': /* comment or whitespace-only */
+ case '\r':
case ' ':
case '\t':
case ';':
diff --git a/tests/config/read.c b/tests/config/read.c
index 25a4fca..23dfbe7 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -703,3 +703,33 @@ void test_config_read__path(void)
git_buf_free(&expected_path);
git_config_free(cfg);
}
+
+void test_config_read__crlf_style_line_endings(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+ git_config *cfg;
+
+ cl_set_cleanup(&clean_test_config, NULL);
+ cl_git_mkfile("./testconfig", "[some]\r\n var = value\r\n");
+ cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
+ cl_assert_equal_s(buf.ptr, "value");
+
+ git_config_free(cfg);
+ git_buf_free(&buf);
+}
+
+void test_config_read__trailing_crlf(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+ git_config *cfg;
+
+ cl_set_cleanup(&clean_test_config, NULL);
+ cl_git_mkfile("./testconfig", "[some]\r\n var = value\r\n\r\n");
+ cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
+ cl_assert_equal_s(buf.ptr, "value");
+
+ git_config_free(cfg);
+ git_buf_free(&buf);
+}