summaryrefslogtreecommitdiff
path: root/git-rebase--interactive.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-05-13 20:47:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-05-14 17:37:29 (GMT)
commit268ef4d3d07e4cf9909ac060b63b195509391190 (patch)
tree4622a1b60e1759caeb8948751d3c9f009520931c /git-rebase--interactive.sh
parent2a86cb6dc4fbc894df1e858d94cdd45c26ccf9d0 (diff)
downloadgit-268ef4d3d07e4cf9909ac060b63b195509391190.zip
git-268ef4d3d07e4cf9909ac060b63b195509391190.tar.gz
git-268ef4d3d07e4cf9909ac060b63b195509391190.tar.bz2
always quote shell arguments to test -z/-n
In shell code like: test -z $foo test -n $foo that does not quote its arguments, it's easy to think that it is actually looking at the contents of $foo in each case. But if $foo is empty, then "test" does not see any argument at all! The results are quite subtle. POSIX specifies that test's behavior depends on the number of arguments it sees, and if $foo is empty, it sees only one. The behavior in this case is: 1 argument: Exit true (0) if $1 is not null; otherwise, exit false. So in the "-z $foo" case, if $foo is empty, then we check that "-z" is non-null, and it returns success. Which happens to match what we expected. But for "-n $foo", if $foo is empty, we'll see that "-n" is non-null and still return success. That's the opposite of what we intended! Furthermore, if $foo contains whitespace, we'll end up with more than 2 arguments. The results in this case are generally unspecified (unless the first part of $foo happens to be a valid binary operator, in which case the results are specified but certainly not what we intended). And on top of this, even though "test -z $foo" _should_ work for the empty case, some older shells (reportedly ksh88) complain about the missing argument. So let's make sure we consistently quote our variable arguments to "test". After this patch, the results of: git grep 'test -[zn] [^"]' are empty. Reported-by: Armin Kunaschik <megabreit@googlemail.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-rebase--interactive.sh')
-rw-r--r--git-rebase--interactive.sh4
1 files changed, 2 insertions, 2 deletions
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 9ea3075..470413b 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -866,12 +866,12 @@ add_exec_commands () {
# $3: the input filename
check_commit_sha () {
badsha=0
- if test -z $1
+ if test -z "$1"
then
badsha=1
else
sha1_verif="$(git rev-parse --verify --quiet $1^{commit})"
- if test -z $sha1_verif
+ if test -z "$sha1_verif"
then
badsha=1
fi