]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sq_quote_buf_pretty: don't drop empty arguments
authorGarima Singh <garima.singh@microsoft.com>
Mon, 7 Oct 2019 19:38:56 +0000 (12:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Oct 2019 03:59:29 +0000 (12:59 +0900)
Empty arguments passed on the command line can be represented by
a '', however sq_quote_buf_pretty was incorrectly dropping these
arguments altogether. Fix this problem by ensuring that such
arguments are emitted as '' instead.

Signed-off-by: Garima Singh <garima.singh@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
quote.c
t/t0014-alias.sh

diff --git a/quote.c b/quote.c
index 7f2aa6faa43fed0cd19f23f6fcfdc7b0ebea5c01..6deef8712b5b7b68629200f3577f3faa758aa5c2 100644 (file)
--- a/quote.c
+++ b/quote.c
@@ -48,6 +48,12 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
        static const char ok_punct[] = "+,-./:=@_^";
        const char *p;
 
+       /* Avoid losing a zero-length string by adding '' */
+       if (!*src) {
+               strbuf_addstr(dst, "''");
+               return;
+       }
+
        for (p = src; *p; p++) {
                if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
                        sq_quote_buf(dst, src);
index a070e645d7fbea6486ff60ee94d7f6df72d84cc6..2694c81afd0a02aeb9a4bba2cd0bcd42b6ea4113 100755 (executable)
@@ -37,4 +37,11 @@ test_expect_success 'looping aliases - internal execution' '
 #      test_i18ngrep "^fatal: alias loop detected: expansion of" output
 #'
 
+test_expect_success 'run-command formats empty args properly' '
+    GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
+    sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
+    echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
+    test_cmp expect actual
+'
+
 test_done