config: also allow escaping outside of a quoted string This limitation was a misparsing of the documentation.
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
diff --git a/src/config_file.c b/src/config_file.c
index c0fa8be..5cc15d4 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1157,12 +1157,6 @@ static char *fixup_line(const char *ptr, int quote_count)
*out++ = '\\';
goto out;
}
- /* otherwise, the backslash must be inside quotes */
- if ((quote_count % 2) == 0) {
- git__free(str);
- giterr_set(GITERR_CONFIG, "Invalid escape at %s", ptr);
- return NULL;
- }
if ((esc = strchr(escapes, *ptr)) != NULL) {
*out++ = escaped[esc - escapes];
} else {
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index 26e6f42..d820af5 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -179,6 +179,18 @@ void test_config_read__prefixes(void)
git_config_free(cfg);
}
+void test_config_read__escaping_quotes(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
+ cl_git_pass(git_config_get_string(cfg, "core.editor", &str));
+ cl_assert(strcmp(str, "\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"") == 0);
+
+ git_config_free(cfg);
+}
+
#if 0
BEGIN_TEST(config10, "a repo's config overrides the global config")