sq_quote_buf_pretty: don't drop empty arguments

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>

Garima Singh committed Oct 7, 2019 at 12:38 UTC ce2d7ed2fd454d60a0957508141438f26c4100c7
2 files changed +13
quote.c
+6
@@ -48,6 +48,12 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
48 static const char ok_punct[] = "+,-./:=@_^";
49 const char *p;
50
51 + /* Avoid losing a zero-length string by adding '' */
52 + if (!*src) {
53 + strbuf_addstr(dst, "''");
54 + return;
55 + }
56 +
57 for (p = src; *p; p++) {
58 if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
59 sq_quote_buf(dst, src);
t/t0014-alias.sh
+7
@@ -37,4 +37,11 @@ test_expect_success 'looping aliases - internal execution' '
37 # test_i18ngrep "^fatal: alias loop detected: expansion of" output
38 #'
39
40 +test_expect_success 'run-command formats empty args properly' '
41 + GIT_TRACE=1 git frotz a "" b " " c 2>&1 |
42 + sed -ne "/run_command:/s/.*trace: run_command: //p" >actual &&
43 + echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
44 + test_cmp expect actual
45 +'
46 +
47 test_done