Skip to content

Commit

Permalink
config: Keep inner whitespace verbatim
Browse files Browse the repository at this point in the history
Configuration values are expected to be quoted when they have leading or
trailing whitespace, but inner whitespace should be kept verbatim even if
the value is not quoted. This is already documented in git-config(1), but
the code caused inner whitespace to be collapsed to a single space,
breaking, for example, clones from a path that has two consecutive spaces
in it, as future fetches would only see a single space.

Reported-by: John te Bokkel <tanj.tanj@gmail.com>
Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Björn Steinbrink authored and Junio C Hamano committed Jul 31, 2009
1 parent e276f01 commit ebdaae3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 4 additions & 6 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ static char *parse_value(void)
if (comment)
continue;
if (isspace(c) && !quote) {
space = 1;
if (len)
space++;
continue;
}
if (!quote) {
Expand All @@ -71,11 +72,8 @@ static char *parse_value(void)
continue;
}
}
if (space) {
if (len)
value[len++] = ' ';
space = 0;
}
for (; space; space--)
value[len++] = ' ';
if (c == '\\') {
c = get_next_char();
switch (c) {
Expand Down
5 changes: 5 additions & 0 deletions t/t1300-repo-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,11 @@ echo >>result

test_expect_success '--null --get-regexp' 'cmp result expect'

test_expect_success 'inner whitespace kept verbatim' '
git config section.val "foo bar" &&
test "z$(git config section.val)" = "zfoo bar"
'

test_expect_success SYMLINKS 'symlinked configuration' '
ln -s notyet myconfig &&
Expand Down

0 comments on commit ebdaae3

Please sign in to comment.