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 <tanj.tanj@gmail.com> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Björn Steinbrink committed
Jul 30, 2009 at 13:41 UTC
ebdaae372b460ffdf5d153dcd0ac235d52b0d2ce
2 files changed
+9
-6
config.c
+4
-6
@@ -62,7 +62,8 @@ static char *parse_value(void)
62
if (comment)
63
continue;
64
if (isspace(c) && !quote) {
65
- space = 1;
65
+ if (len)
66
+ space++;
67
continue;
68
}
69
if (!quote) {
@@ -71,11 +72,8 @@ static char *parse_value(void)
72
continue;
73
}
74
}
74
- if (space) {
75
- if (len)
76
- value[len++] = ' ';
77
- space = 0;
78
- }
75
+ for (; space; space--)
76
+ value[len++] = ' ';
77
if (c == '\\') {
78
c = get_next_char();
79
switch (c) {
t/t1300-repo-config.sh
+5
@@ -733,6 +733,11 @@ echo >>result
733
734
test_expect_success '--null --get-regexp' 'cmp result expect'
735
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
+
741
test_expect_success SYMLINKS 'symlinked configuration' '
742
743
ln -s notyet myconfig &&