[PATCH 2/8] config.c: Escape backslashes in section names properly

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Bryan Donlan
Date: Tuesday, April 8, 2008 - 6:29 pm

Signed-off-by: Bryan Donlan <bdonlan@fushizen.net>
---
 config.c                |    2 +-
 t/t1303-wacky-config.sh |    6 ++++++
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/config.c b/config.c
index 0624494..6c07245 100644
--- a/config.c
+++ b/config.c
@@ -672,7 +672,7 @@ static int store_write_section(int fd, const char* key)
 	if (dot) {
 		strbuf_addf(&sb, "[%.*s \"", (int)(dot - key), key);
 		for (i = dot - key + 1; i < store.baselen; i++) {
-			if (key[i] == '"')
+			if (key[i] == '"' || key[i] == '\\')
 				strbuf_addch(&sb, '\\');
 			strbuf_addch(&sb, key[i]);
 		}
diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh
index 99985dc..f366b53 100755
--- a/t/t1303-wacky-config.sh
+++ b/t/t1303-wacky-config.sh
@@ -34,4 +34,10 @@ test_expect_success 'add key in different section' '
 	check section2.key bar
 '
 
+SECTION="test.q\"s\\sq'sp e.key"
+test_expect_success 'make sure git-config escapes section names properly' '
+	git config "$SECTION" bar &&
+	check "$SECTION" bar
+'
+
 test_done
-- 
1.5.5.8.gbbd98

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2/8] config.c: Escape backslashes in section names ..., Bryan Donlan, (Tue Apr 8, 6:29 pm)
[PATCH 4/8] test-lib.sh: Fix some missing path quoting, Bryan Donlan, (Tue Apr 8, 6:30 pm)
[PATCH 7/8] Use test_set_editor in t9001-send-email.sh, Bryan Donlan, (Tue Apr 8, 6:30 pm)