git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: "Garima Singh via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: garimasigit@gmail.com, jeffhost@microsoft.com, stolee@gmail.com,
	Junio C Hamano <gitster@pobox.com>,
	Garima Singh <garima.singh@microsoft.com>
Subject: [PATCH v2 1/1] quote: handle null and empty strings in sq_quote_buf_pretty()
Date: Mon, 26 Aug 2019 07:44:44 -0700 (PDT)	[thread overview]
Message-ID: <b9a68598d79724849995283e6967f1c52843c048.1566830682.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.314.v2.git.gitgitgadget@gmail.com>

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

  reply	other threads:[~2019-08-26 14:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-20 19:35 [PATCH 0/1] " Garima Singh via GitGitGadget
2019-08-20 19:35 ` [PATCH 1/1] " Garima Singh via GitGitGadget
2019-08-20 20:29   ` Junio C Hamano
2019-08-21 15:22     ` Junio C Hamano
2019-08-20 20:32   ` Junio C Hamano
2019-08-26 14:44 ` [PATCH v2 0/1] " Garima Singh via GitGitGadget
2019-08-26 14:44   ` Garima Singh via GitGitGadget [this message]
2019-08-26 15:24     ` [PATCH v2 1/1] " Garima Singh
2019-08-26 16:20       ` Junio C Hamano
2019-10-07 16:17   ` [PATCH v3 0/1] " Garima Singh via GitGitGadget
2019-10-07 16:17     ` [PATCH v3 1/1] quote: handle numm and empty strings in sq_quote_buf_pretty Garima Singh via GitGitGadget
2019-10-07 17:08       ` Garima Singh
2019-10-07 17:27       ` Eric Sunshine
2019-10-07 17:47         ` Garima Singh
2019-10-07 19:38     ` [PATCH v4 0/1] quote: handle null and empty strings in sq_quote_buf_pretty() Garima Singh via GitGitGadget
2019-10-07 19:38       ` [PATCH v4 1/1] sq_quote_buf_pretty: don't drop empty arguments Garima Singh via GitGitGadget
2019-10-08  3:16         ` Junio C Hamano
2019-10-08 16:40       ` [PATCH v5 0/1] quote: handle null and empty strings in sq_quote_buf_pretty() Garima Singh via GitGitGadget
2019-10-08 16:40         ` [PATCH v5 1/1] sq_quote_buf_pretty: don't drop empty arguments Garima Singh via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b9a68598d79724849995283e6967f1c52843c048.1566830682.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=garima.singh@microsoft.com \
    --cc=garimasigit@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    --cc=stolee@gmail.com \
    --subject='Re: [PATCH v2 1/1] quote: handle null and empty strings in sq_quote_buf_pretty()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).