Commit 848153f3 by Patrick Steinhardt

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.
parent 5340ca77
......@@ -495,6 +495,7 @@ int git_config_parse(
break;
case '\n': /* comment or whitespace-only */
case '\r':
case ' ':
case '\t':
case ';':
......
......@@ -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);
}
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