Skip to content

Commit

Permalink
config.c: Escape backslashes in section names properly
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bryan Donlan authored and Junio C Hamano committed May 5, 2008
1 parent 97b88dd commit e5c349b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,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]);
}
Expand Down
6 changes: 6 additions & 0 deletions t/t1303-wacky-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e5c349b

Please sign in to comment.