Skip to content

Commit ebdaae3

Browse files
dotdashgitster
authored andcommitted
config: Keep inner whitespace verbatim
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 <[email protected]> Signed-off-by: Björn Steinbrink <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e276f01 commit ebdaae3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

config.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static char *parse_value(void)
6262
if (comment)
6363
continue;
6464
if (isspace(c) && !quote) {
65-
space = 1;
65+
if (len)
66+
space++;
6667
continue;
6768
}
6869
if (!quote) {
@@ -71,11 +72,8 @@ static char *parse_value(void)
7172
continue;
7273
}
7374
}
74-
if (space) {
75-
if (len)
76-
value[len++] = ' ';
77-
space = 0;
78-
}
75+
for (; space; space--)
76+
value[len++] = ' ';
7977
if (c == '\\') {
8078
c = get_next_char();
8179
switch (c) {

t/t1300-repo-config.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ echo >>result
733733

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

736+
test_expect_success 'inner whitespace kept verbatim' '
737+
git config section.val "foo bar" &&
738+
test "z$(git config section.val)" = "zfoo bar"
739+
'
740+
736741
test_expect_success SYMLINKS 'symlinked configuration' '
737742
738743
ln -s notyet myconfig &&

0 commit comments

Comments
 (0)