Merge pull request #1771 from nvloff/write_empty_config_value config: allow setting empty string as value
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
diff --git a/src/config_file.c b/src/config_file.c
index 570f286..1d7b4fb 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1304,6 +1304,9 @@ static char *escape_value(const char *ptr)
assert(ptr);
len = strlen(ptr);
+ if (!len)
+ return git__calloc(1, sizeof(char));
+
git_buf_grow(&buf, len);
while (*ptr != '\0') {
diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c
index d70612a..57b02a7 100644
--- a/tests-clar/config/write.c
+++ b/tests-clar/config/write.c
@@ -242,3 +242,20 @@ void test_config_write__can_set_a_value_to_NULL(void)
cl_git_sandbox_cleanup();
}
+
+void test_config_write__can_set_an_empty_value(void)
+{
+ git_repository *repository;
+ git_config *config;
+ const char * str;
+
+ repository = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_repository_config(&config, repository));
+
+ cl_git_pass(git_config_set_string(config, "core.somevar", ""));
+ cl_git_pass(git_config_get_string(&str, config, "core.somevar"));
+ cl_assert_equal_s(str, "");
+
+ git_config_free(config);
+ cl_git_sandbox_cleanup();
+}