From ebdaae372b460ffdf5d153dcd0ac235d52b0d2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Thu, 30 Jul 2009 13:41:57 +0200 Subject: config: Keep inner whitespace verbatim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Björn Steinbrink Signed-off-by: Junio C Hamano --- config.c | 10 ++++------ t/t1300-repo-config.sh | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config.c b/config.c index 1682273c12..7e5594b65e 100644 --- a/config.c +++ b/config.c @@ -62,7 +62,8 @@ static char *parse_value(void) if (comment) continue; if (isspace(c) && !quote) { - space = 1; + if (len) + space++; continue; } if (!quote) { @@ -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) { diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 43ea283242..91cbd551d8 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -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 && -- cgit v1.2.3