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:
Garima Singh
2019-10-07 12:38:56 -07:00
committed by Junio C Hamano
parent 5fa0f5238b
commit ce2d7ed2fd
2 changed files with 13 additions and 0 deletions

View File

@@ -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);