config.c: Escape backslashes in section names properly
If an element of the configuration key name other than the first or last contains a backslash, it is not escaped on output, but is treated as an escape sequence on input. Thus, the backslash is lost when re-loading the configuration. This patch corrects this by having backslashes escaped properly, and introduces a new test for this bug. Signed-off-by: Bryan Donlan <bdonlan@fushizen.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Bryan Donlan committed
May 4, 2008 at 01:37 UTC
e5c349ba112fc53832c757cef122297718d3a175
2 files changed
+7
-1
config.c
+1
-1
@@ -680,7 +680,7 @@ static int store_write_section(int fd, const char* key)
680
if (dot) {
681
strbuf_addf(&sb, "[%.*s \"", (int)(dot - key), key);
682
for (i = dot - key + 1; i < store.baselen; i++) {
683
- if (key[i] == '"')
683
+ if (key[i] == '"' || key[i] == '\\')
684
strbuf_addch(&sb, '\\');
685
strbuf_addch(&sb, key[i]);
686
}
t/t1303-wacky-config.sh
+6
@@ -34,4 +34,10 @@ test_expect_success 'add key in different section' '
34
check section2.key bar
35
'
36
37
+SECTION="test.q\"s\\sq'sp e.key"
38
+test_expect_success 'make sure git-config escapes section names properly' '
39
+ git config "$SECTION" bar &&
40
+ check "$SECTION" bar
41
+'
42
+
43
test_done