From: Phillip Wood <phillip.wood123@gmail.com>
To: "D. Ben Knoble" <ben.knoble@gmail.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Cc: git@vger.kernel.org, Harald Nordgren <haraldnordgren@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
MD Nahid Hasan Sagor <nahidhasan141400@gmail.com>
Subject: Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier
Date: Mon, 30 Nov 2026 16:38:24 +0000 [thread overview]
Message-ID: <27a384cb-7279-4061-9925-c55107575f6d@gmail.com> (raw)
In-Reply-To: <CALnO6CDyTh+O_S6Q6Nq46wckLGXdvTKJmU6uK_SKn5S=p4X20g@mail.gmail.com>
Hi Ben
On 30/11/2026 15:19, D. Ben Knoble wrote:
> Hi Phillip, thanks for working on this!
Thanks
> On Fri, Nov 27, 2026 at 11:54 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
>> + for (q = p; *q; q++) {
>> + if (need_bs_quote(*q)) {
>> + if (brace)
>> + quote_it = true;
>> + if (quote_it)
>> + strbuf_addch(dst, '\'');
>> + strbuf_add(dst, p, q - p);
>> + p = q + 1;
>> + if (quote_it)
>> + strbuf_addch(dst, '\'');
>> + strbuf_addch(dst, '\\');
>> + strbuf_addch(dst, *q);
>> + if (!brace)
>> + quote_it = false;
>> + } else if (*q == '{') {
>> + brace++;
>> + } else if (*q == '}' && brace) {
>> + brace--;
>
> I think this simple counter may count wrongly for scenarios like
> "}{a,b}", but I haven't tried it myself yet. My shells (Zsh and Bash)
> both do the following:
>
> $ echo }{a,b}
> }a }b
>
> and I *think* that brace==0 when we see the comma here, even though it
> would need quoted to avoid expansion.
We only decrement "brace" when we see '}' if "brace > 0". If we see '}'
when "brace == 0" then we quote everything up to the next backslash
escape or the end of the string. So we decide to quote this before we
see the comma.
Thanks
Phillip
>
> I think we are unlikely to emit such strange punctuation ourselves,
> but this would be one corner case of potentially many, I suspect.
>
>> + } else if (!quote_it && needs_sq_quote(*q, brace)) {
>> + quote_it = true;
>> + }
>> + }
>> + if (brace && !quote_it)
>> + quote_it = true; /* Quote unpaired '{' */
>> + if (quote_it)
>> + strbuf_addch(dst, '\'');
>> + strbuf_add(dst, p, q - p);
>> + if (quote_it)
>> + strbuf_addch(dst, '\'');
>> }
>>
>> void sq_quotef(struct strbuf *dst, const char *fmt, ...)
>> --
>> 2.56.1.576.g0cfbda1d5c7.dirty
>>
>
>
next prev parent reply other threads:[~2026-11-30 16:39 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
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 [this message]
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=27a384cb-7279-4061-9925-c55107575f6d@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=haraldnordgren@gmail.com \
--cc=nahidhasan141400@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/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