Skip to content

Commit a6a0217

Browse files
committed
sq_quote_buf_pretty: don't drop empty arguments
Empty arguments passed on the command line can be a 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. Reported by: Junio Hamano <[email protected]> Signed-off-by: Garima Singh <[email protected]>
1 parent 5fa0f52 commit a6a0217

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

quote.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
4848
static const char ok_punct[] = "+,-./:=@_^";
4949
const char *p;
5050

51+
if (!src)
52+
BUG("Cannot append a NULL token to the buffer");
53+
54+
/* Avoid losing a zero-length string by adding '' */
55+
if (!*src) {
56+
strbuf_addstr(dst, "''");
57+
return;
58+
}
59+
5160
for (p = src; *p; p++) {
5261
if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
5362
sq_quote_buf(dst, src);

t/t0014-alias.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ test_expect_success 'looping aliases - internal execution' '
3737
# test_i18ngrep "^fatal: alias loop detected: expansion of" output
3838
#'
3939

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+
4047
test_done

0 commit comments

Comments
 (0)