From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Armin Kunaschik <megabreit@googlemail.com>,
Git List <git@vger.kernel.org>
Subject: [PATCH 0/6] test -z/-n quoting fix + misc cleanups
Date: Fri, 13 May 2016 16:46:54 -0400 [thread overview]
Message-ID: <20160513204654.GA10684@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqshxl9142.fsf@gitster.mtv.corp.google.com>
On Fri, May 13, 2016 at 01:03:41PM -0700, Junio C Hamano wrote:
> > And sadly,
> >
> > git grep 'test -n [^"]'
> >
> > is not empty.
>
> Are you doing an audit? Otherwise I'm interested in taking a brief
> look.
There was only one buggy case there (in git-stash). The rest were false
positives.
I didn't audit for:
test $foo = bar
which also has problems. You can grep for:
git grep 'test \$'
and there are a lot of hits. Many of them are probably fine, if they are
variables that are known to be non-empty and not contain whitespace
(e.g., $#). But some of them are questionable, like:
git-request-pull.sh:if test $(git cat-file -t "$head") = tag
I suspect in practice that's fine just because we're likely to see
either the empty string (in which case test will barf with "unary
operator expected", which matches what we want), or a single-word
response (which doesn't need further quoting).
> >> But working around older/broken shells is easy and the resulting
> >> script it more readable, so let's take this. It makes the resulting
> >> code easier to understand even when we know we run it under POSIX
> >> shell.
Actually, it's not just older shells:
foo='bar baz'
test -z $foo
is "unspecified" according to POSIX, though in practice it will complain
about "binary operator expected". You can get some weirdness, though,
like:
foo='!= bar'
test -z $foo
which returns 0. Unlikely, but still clearly wrong for us not to be
quoting.
Anyway. Here's a series that fixes the -n/-z cases, along with a bunch
of cleanups that remove the false positives (most of which I sent out
just a few minutes ago as "minor fixes to some svn tests").
[1/6]: t/lib-git-svn: drop $remote_git_svn and $git_svn_id
[2/6]: t9100,t3419: enclose all test code in single-quotes
[3/6]: t9107: use "return 1" instead of "exit 1"
[4/6]: t9107: switch inverted single/double quotes in test
[5/6]: t9103: modernize test style
[6/6]: always quote shell arguments to test -z/-n
You could take just 6/6 as its own series; the rest are just about
removing the false positives, and fixing other issues. I put it last,
though, because otherwise the "this grep is now empty" claim in it is
not true. :)
-Peff
next prev parent reply other threads:[~2016-05-13 20:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-13 16:09 t3404 static check of bad SHA-1 failure Armin Kunaschik
2016-05-13 18:23 ` Jeff King
2016-05-13 19:52 ` Junio C Hamano
2016-05-13 19:59 ` Jeff King
2016-05-13 20:02 ` Jeff King
2016-05-13 20:03 ` Junio C Hamano
2016-05-13 20:46 ` Jeff King [this message]
2016-05-13 20:47 ` [PATCH 1/6] t/lib-git-svn: drop $remote_git_svn and $git_svn_id Jeff King
2016-05-13 20:47 ` [PATCH 2/6] t9100,t3419: enclose all test code in single-quotes Jeff King
2016-05-13 20:47 ` [PATCH 3/6] t9107: use "return 1" instead of "exit 1" Jeff King
2016-05-13 22:59 ` Eric Wong
2016-05-13 23:45 ` Eric Sunshine
2016-05-13 23:47 ` Jeff King
2016-05-14 17:37 ` Junio C Hamano
2016-05-14 19:51 ` Jeff King
2016-05-13 20:47 ` [PATCH 4/6] t9107: switch inverted single/double quotes in test Jeff King
2016-05-13 20:47 ` [PATCH 5/6] t9103: modernize test style Jeff King
2016-05-13 20:47 ` [PATCH 6/6] always quote shell arguments to test -z/-n Jeff King
2016-05-13 22:09 ` [PATCH 0/6] test -z/-n quoting fix + misc cleanups 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160513204654.GA10684@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=megabreit@googlemail.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;
as well as URLs for NNTP newsgroup(s).