Subject: [PATCH v4 0/1] quote: handle null and empty strings in sq_quote_buf_pretty()

From: "Garima Singh via GitGitGadget" <[email-masked]>
Date: Mon, 07 Oct 2019 12:38:56 -0700 (PDT)

Hey,

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.

Looking forward to your review. Cheers! Garima Singh

Reported by: Junio Hamano [email-masked] [[email-masked]] in
https://public-inbox.org/git/[email-masked]/T/#m9e33936067ec2066f675aa63133a2486efd415fd

Garima Singh (1):
  sq_quote_buf_pretty: don't drop empty arguments

 quote.c          | 9 +++++++++
 t/t0014-alias.sh | 7 +++++++
 2 files changed, 16 insertions(+)

base-commit: 5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-314%2Fgarimasi514%2FcoreGit-fixQuote-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-314/garimasi514/coreGit-fixQuote-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/314

Range-diff vs v3:

 1:  399fe02cb1 ! 1:  a6a0217ce6 quote: handle numm and empty strings in sq_quote_buf_pretty
     @@ -1,13 +1,11 @@
      Author: Garima Singh <[email-masked]>
      
     -    quote: handle numm and empty strings in sq_quote_buf_pretty
     +    sq_quote_buf_pretty: don't drop empty arguments
      
     -    The sq_quote_buf_pretty() function does not emit anything
     -    when the incoming string is empty, but the function is to
     -    accumulate command line arguments, properly quoted as
     -    necessary, and the right way to add an argument that is an
     -    empty string is to show it quoted, i.e. ''. We warn the caller
     -    with the BUG macro is they pass in a NULL.
     +    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-masked]>
          Signed-off-by: Garima Singh <[email-masked]>
     @@ -19,11 +17,10 @@
       	static const char ok_punct[] = "+,-./:=@_^";
       	const char *p;
       
     -+	/* In case of null tokens, warn the user of the BUG in their call. */
      +	if (!src) 
      +		BUG("Cannot append a NULL token to the buffer");
      +	
     -+	/* Avoid dropping a zero-length token by adding '' */
     ++	/* Avoid losing a zero-length string by adding '' */ 
      +	if (!*src) {
      +		strbuf_addstr(dst, "''");
      +		return;
     @@ -40,7 +37,7 @@
       #	test_i18ngrep "^fatal: alias loop detected: expansion of" output
       #'
       
     -+test_expect_success 'run-command parses empty args properly, using sq_quote_buf_pretty' '
     ++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 &&

-- 
gitgitgadget