From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: git@vger.kernel.org, Ben Knoble <ben.knoble@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>,
MD Nahid Hasan Sagor <nahidhasan141400@gmail.com>
Subject: Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier
Date: Fri, 27 Nov 2026 12:31:18 -0800 [thread overview]
Message-ID: <xmqq7bhy819l.fsf@gitster.g> (raw)
In-Reply-To: <ee7de58093c69fbbab686a68b5b781bc60d90a2b.1795798429.git.phillip.wood@dunelm.org.uk> (Phillip Wood's message of "Fri, 27 Nov 2026 16:54:27 +0000")
Phillip Wood <phillip.wood123@gmail.com> writes:
> +static bool needs_sq_quote(char c, unsigned brace)
> +{
> + if (isalnum(c) || (unsigned char)c > 0x7f)
> + return false;
> +
> + switch (c) {
> + case ',':
> + return brace > 0; /* Prevent brace expansion */
Web search tells me that bash, zsh, and ksh93 expands sequence
expressions such as "{1..5}" or "{a..z}" without any comma in the pair
of braces. Because '.' returns false unconditionally here and no other
check triggers quoting for "..", sq_quote_buf_pretty() leaves "{1..5}"
unquoted, which expands to five arguments if pasted into those shells.
> void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
> {
> - static const char ok_punct[] = "+,-./:=@_^";
> - const char *p;
> + const char *p = src, *q;
> + bool quote_it = false;
> + unsigned brace = 0;
>
> /* Avoid losing a zero-length string by adding '' */
> - if (!*src) {
> + if (!*p) {
> strbuf_addstr(dst, "''");
> return;
> }
>
> - for (p = src; *p; p++) {
> - if (!isalnum(*p) && !strchr(ok_punct, *p)) {
> - sq_quote_buf(dst, src);
> - return;
> - }
> + /* '~' is only special if it is the first character */
> + if (*p == '~') {
> + quote_it = true;
> + p++;
> }
As noticed by Nahid already, this loses the leading '~'. Also, do we
want to do something to this corner case?
$ echo P=A:~/B:C
P=A:/home/gitster/B:C
i.e., bash and friends seem to expand ~ that is not at the beginning of
value when the whole thing looks like a variable assignment. Without
"P=" at front, this does not seem to expand.
Thanks.
next prev parent reply other threads:[~2026-11-27 20:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 16:54 [RFC PATCH] quote: make sq_quote_buf_pretty() prettier Phillip Wood
2026-11-27 18:25 ` Nahid hasan Sagor
2026-11-30 14:51 ` Phillip Wood
2026-11-27 20:31 ` Junio C Hamano [this message]
2026-11-30 16:39 ` Phillip Wood
2026-11-28 0:26 ` Junio C Hamano
2026-11-30 16:40 ` Phillip Wood
2026-11-30 15:19 ` D. Ben Knoble
2026-11-30 16:38 ` Phillip Wood
2026-11-30 17:02 ` D. Ben Knoble
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq7bhy819l.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=haraldnordgren@gmail.com \
--cc=nahidhasan141400@gmail.com \
--cc=phillip.wood123@gmail.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox