sh: Fix ""$@, which should not use the special case for "$@".
"$@" should expand to no words if there are no positional parameters, but ""$@ should always expand to at least an empty word.
This commit is contained in:
parent
b5240dc194
commit
cf0d26dcd6
@ -249,7 +249,8 @@ argstr(char *p, int flag)
|
||||
case CTLQUOTEMARK:
|
||||
lit_quoted = 1;
|
||||
/* "$@" syntax adherence hack */
|
||||
if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
|
||||
if (p[0] == CTLVAR && (p[1] & VSQUOTE) != 0 &&
|
||||
p[2] == '@' && p[3] == '=')
|
||||
break;
|
||||
if ((flag & EXP_FULL) != 0)
|
||||
USTPUTC(c, expdest);
|
||||
|
31
bin/sh/tests/parameters/positional8.0
Normal file
31
bin/sh/tests/parameters/positional8.0
Normal file
@ -0,0 +1,31 @@
|
||||
# $FreeBSD$
|
||||
|
||||
failures=''
|
||||
ok=''
|
||||
|
||||
testcase() {
|
||||
code="$1"
|
||||
expected="$2"
|
||||
oIFS="$IFS"
|
||||
eval "$code"
|
||||
IFS='|'
|
||||
result="$#|$*"
|
||||
IFS="$oIFS"
|
||||
if [ "x$result" = "x$expected" ]; then
|
||||
ok=x$ok
|
||||
else
|
||||
failures=x$failures
|
||||
echo "For $code, expected $expected actual $result"
|
||||
fi
|
||||
}
|
||||
|
||||
testcase 'shift $#; set -- ""$*' '1|'
|
||||
testcase 'shift $#; set -- $*""' '1|'
|
||||
testcase 'shift $#; set -- ""$@' '1|'
|
||||
testcase 'shift $#; set -- $@""' '1|'
|
||||
testcase 'shift $#; set -- """$*"' '1|'
|
||||
testcase 'shift $#; set -- "$*"""' '1|'
|
||||
testcase 'shift $#; set -- """$@"' '1|'
|
||||
testcase 'shift $#; set -- "$@"""' '1|'
|
||||
|
||||
test "x$failures" = x
|
Loading…
Reference in New Issue
Block a user