summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-02-08 10:02:29 +0000
committerPatrick Steinhardt <ps@pks.im>2018-02-08 17:13:53 +0000
commit848153f386b45363d033c72e155e4001d0217f96 (patch)
tree9aed7a3bc66253f2ffdf2317ef7e1511eb701764
parent5340ca774cbe702eb0115e74b559884003c61232 (diff)
downloadlibgit2-848153f386b45363d033c72e155e4001d0217f96.tar.gz
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.
-rw-r--r--src/config_parse.c1
-rw-r--r--tests/config/read.c30
2 files changed, 31 insertions, 0 deletions
diff --git a/src/config_parse.c b/src/config_parse.c
index 2b9669c2b..981f968bb 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 25a4fcaf4..23dfbe7bb 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);
+}