git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/1] quote: handle null and empty strings in sq_quote_buf_pretty()

From
GSGarima Singh <garimasigit@gmail.com>
Date
Aug 26, 2019, 15:24 UTC
Message-ID
<CAN+QWEZU2FqkH1jWnv==owKLsMk8XNXJh6PpF6njvB6MmKt+Dw@mail.gmail.com>
In-Reply-To
<b9a68598d79724849995283e6967f1c52843c048.1566830682.git.gitgitgadget@gmail.com>

Thanks for the review Junio! I really appreciate it and look forward to hear what you think of the updated patch.

Cheers! Garima Singh

On Mon, Aug 26, 2019 at 10:44 AM Garima Singh via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 59 quoted lines
>
> From: Garima Singh <garima.singh@microsoft.com>
>
> 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 if they
> pass in a NULL.
>
> Reported by: Junio Hamano <gitster@pobox.com>
> Signed-off-by: Garima Singh <garima.singh@microsoft.com>
> ---
>  quote.c          | 12 ++++++++++++
>  t/t0014-alias.sh |  8 ++++++++
>  2 files changed, 20 insertions(+)
>
> diff --git a/quote.c b/quote.c
> index 7f2aa6faa4..6d0f8a22a9 100644
> --- a/quote.c
> +++ b/quote.c
> @@ -48,6 +48,18 @@ void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
>         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("BUG can't append a NULL token to the buffer");
> +
> +       /* In case of empty tokens, add a '' to ensure they
> +        * don't get inadvertently dropped.
> +        */
> +       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);
> diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
> index a070e645d7..9c176c7cbb 100755
> --- a/t/t0014-alias.sh
> +++ b/t/t0014-alias.sh
> @@ -37,4 +37,12 @@ test_expect_success 'looping aliases - internal execution' '
>  #      test_i18ngrep "^fatal: alias loop detected: expansion of" output
>  #'
>
> +test_expect_success 'run-command parses empty args properly, using sq_quote_buf_pretty' '
> +       cat >expect <<-EOF &&
> +       fatal: cannot change to '\''alias.foo=frotz foo '\'''\'' bar'\'': No such file or directory
> +       EOF
> +       test_expect_code 128 git -C "alias.foo=frotz foo '\'''\'' bar" foo 2>actual &&
> +       test_cmp expect actual
> +'
> +
>  test_done
> --
> gitgitgadget
Previous: Garima Singh via GitGitGadgetNext: Junio C Hamano
Message 8 of 19 in “quote: handle null and empty strings in sq_quote_buf_pretty()”
  1. 0/1 quote: handle null and empty strings in sq_quote_buf_pretty()Garima Singh via GitGitGadget, Aug 20, 2019
  2. 1/1 quote: handle null and empty strings in sq_quote_buf_pretty()Garima Singh via GitGitGadget, Aug 20, 2019
  3. Junio C HamanoAug 20, 2019
  4. Junio C HamanoAug 21, 2019
  5. Junio C HamanoAug 20, 2019
  6. 0/1 quote: handle null and empty strings in sq_quote_buf_pretty()Garima Singh via GitGitGadget, Aug 26, 2019
  7. 1/1 quote: handle null and empty strings in sq_quote_buf_pretty()Garima Singh via GitGitGadget, Aug 26, 2019
  8. Garima SinghAug 26, 2019
  9. Junio C HamanoAug 26, 2019
  10. 0/1 quote: handle null and empty strings in sq_quote_buf_pretty()Garima Singh via GitGitGadget, Oct 7, 2019
  11. 1/1 quote: handle numm and empty strings in sq_quote_buf_prettyGarima Singh via GitGitGadget, Oct 7, 2019
  12. Garima SinghOct 7, 2019
  13. Eric SunshineOct 7, 2019
  14. Garima SinghOct 7, 2019
  15. 0/1 quote: handle null and empty strings in sq_quote_buf_pretty()Garima Singh via GitGitGadget, Oct 7, 2019
  16. 1/1 sq_quote_buf_pretty: don't drop empty argumentsGarima Singh via GitGitGadget, Oct 7, 2019
  17. Junio C HamanoOct 8, 2019
  18. 0/1 quote: handle null and empty strings in sq_quote_buf_pretty()Garima Singh via GitGitGadget, Oct 8, 2019
  19. 1/1 sq_quote_buf_pretty: don't drop empty argumentsGarima Singh via GitGitGadget, Oct 8, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.