Skip to content

Commit

Permalink
t1507: avoid "${parameter<op>'word'}" inside double-quotes
Browse files Browse the repository at this point in the history
Kacper Kornet noticed that a $variable in "word" in the above construct is
not substituted by his pdksh.  Modern POSIX compliant shells (e.g. dash,
ksh, bash) all seem to interpret POSIX "2.6.2 Parameter Expansion" that
says "word shall be subjected to tilde expansion, parameter expansion,
command substitution, and arithmetic expansion" in ${parameter<op>word},
to mean that the word is expanded as if it appeared in dq pairs, so if the
word were "'$variable'" (sans dq) it would expand to a single quote, the
value of the $variable and then a single quote.

Johannes Sixt reports that the behavior of quoting at the right of :- when
the ${...:-...} expansion appears in double-quotes was debated recently at
length at the Austin group.  We can avoid this issue and future-proof the
test by a slight rewrite.

Helped-by: Johannes Sixt <j.sixt@viscovery.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed May 9, 2011
1 parent e41d718 commit 365c2aa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions t/t1506-rev-parse-diagnosis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ exec </dev/null

test_did_you_mean ()
{
printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected &&
printf "Did you mean '$1:$2$3'${2:+ aka '$1:./$3'}?\n" >>expected &&
sq="'" &&
cat >expected <<-EOF &&
fatal: Path '$2$3' $4, but not ${5:-$sq$3$sq}.
Did you mean '$1:$2$3'${2:+ aka $sq$1:./$3$sq}?
EOF
test_cmp expected error
}

Expand Down

0 comments on commit 365c2aa

Please sign in to comment.