mirror of
https://github.com/git/git.git
synced 2024-05-13 07:36:09 +02:00
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>
This commit is contained in:
parent
5fa0f5238b
commit
ce2d7ed2fd
6
quote.c
6
quote.c
|
@ -48,6 +48,12 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
|
||||||
static const char ok_punct[] = "+,-./:=@_^";
|
static const char ok_punct[] = "+,-./:=@_^";
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
|
/* Avoid losing a zero-length string by adding '' */
|
||||||
|
if (!*src) {
|
||||||
|
strbuf_addstr(dst, "''");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (p = src; *p; p++) {
|
for (p = src; *p; p++) {
|
||||||
if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
|
if (!isalpha(*p) && !isdigit(*p) && !strchr(ok_punct, *p)) {
|
||||||
sq_quote_buf(dst, src);
|
sq_quote_buf(dst, src);
|
||||||
|
|
|
@ -37,4 +37,11 @@ test_expect_success 'looping aliases - internal execution' '
|
||||||
# test_i18ngrep "^fatal: alias loop detected: expansion of" output
|
# 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
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue