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
1522652230
commit
a5cb58abc8
@ -249,7 +249,8 @@ argstr(char *p, int flag)
|
|||||||
case CTLQUOTEMARK:
|
case CTLQUOTEMARK:
|
||||||
lit_quoted = 1;
|
lit_quoted = 1;
|
||||||
/* "$@" syntax adherence hack */
|
/* "$@" syntax adherence hack */
|
||||||
if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
|
if (p[0] == CTLVAR && (p[1] & VSQUOTE) != 0 &&
|
||||||
|
p[2] == '@' && p[3] == '=')
|
||||||
break;
|
break;
|
||||||
if ((flag & EXP_FULL) != 0)
|
if ((flag & EXP_FULL) != 0)
|
||||||
USTPUTC(c, expdest);
|
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…
x
Reference in New Issue
Block a user