git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Robert Estelle <robertestelle@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Robert Estelle via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] completion: fix incorrect bash/zsh string equality check
Date: Mon, 25 Oct 2021 15:20:04 -0700	[thread overview]
Message-ID: <CAMmwyQqSJRgQ+-tFwYSSw2FU9TJ0TbjP-M_1rJSmo7bFpLW76w@mail.gmail.com> (raw)
In-Reply-To: <xmqqzgrjglma.fsf@gitster.g>

I considered dropping this patch entirely since this discussion was
going so far off the rails for a single-char fix, but I hate to leave
things hanging…

> When you do not mean pattern matching and want exact matching, even
> if it is guaranteed that the data you pass through the codepath does
> not have pattern to cause the former, hence the distinction between
> [[ x == y ]] and [ x = y ] does not make a difference, that is a
> mere happenstance, and use of [ x = y ] is the correct thing to do
> in such a case.

I think you've misread what's going on here, or might be
misremembering the shell quoting rules (which would surprise me!).

My assertion about their equivalence was syntactic: there's no
happenstance or reliance on codepaths whatsoever.
If you write:
  [[ "$x" == "$y" ]]
then it doesn't matter what x and y contain. They're quoted: it's just
a literal string comparison of their values.
Their values can contain quotes, newlines, spaces, asterisks, emoji,
etc. and none of that gets any special interpretation.

Regardless, since they're functionally equivalent, I've pushed up a
change to do it the other way and will submit that shortly.

Best,
Robert

On Fri, Oct 8, 2021 at 4:09 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Robert Estelle <robertestelle@gmail.com> writes:
>
> > The choice between the two does not affect correctness, it's purely
> > stylistic here. It only would affect correctness for unquoted
> > arguments or extended comparison operators. Those *are* in use
> > elsewhere in this script and force the use of `[[` in those places.
> >
> > Keep in mind also that this is an autocomplete script. Although it's
> > sourced by both bash and zsh, it does not make sense to attempt to
> > make it work for bare POSIX sh.
>
> Nobody is trying to.  It is more for reducing the risk of people
> shooting their foot by cutting and pasting without thinking.
>
> When you do not mean pattern matching and want exact matching, even
> if it is guaranteed that the data you pass through the codepath does
> not have pattern to cause the former, hence the distinction between
> [[ x == y ]] and [ x = y ] does not make a difference, that is a
> mere happenstance, and use of [ x = y ] is the correct thing to do
> in such a case.

  reply	other threads:[~2021-10-25 22:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 21:39 [PATCH] completion: fix incorrect bash/zsh string equality check Robert Estelle via GitGitGadget
2021-10-08 20:50 ` Junio C Hamano
2021-10-08 20:57   ` brian m. carlson
2021-10-08 22:17     ` Robert Estelle
2021-10-08 22:05   ` Robert Estelle
2021-10-08 22:16     ` Junio C Hamano
2021-10-08 22:26       ` Robert Estelle
2021-10-08 23:09         ` Junio C Hamano
2021-10-25 22:20           ` Robert Estelle [this message]
2021-10-25 22:29 ` [PATCH v2] " Robert Estelle via GitGitGadget
2021-10-28 16:36   ` Junio C Hamano

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=CAMmwyQqSJRgQ+-tFwYSSw2FU9TJ0TbjP-M_1rJSmo7bFpLW76w@mail.gmail.com \
    --to=robertestelle@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.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.
Code repositories for project(s) associated with this public 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).