summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2015-11-18 21:09:03 +0000
committerjilles <jilles@FreeBSD.org>2015-11-18 21:09:03 +0000
commitcf0d26dcd6f3ae0595b32f615c52e365a58478c0 (patch)
tree7ccc5ddee96c6a52ecb1e104b67ce2610af523e4 /bin/sh
parentb5240dc1944697c0e8cfcbde23981eab5936e502 (diff)
downloadFreeBSD-src-cf0d26dcd6f3ae0595b32f615c52e365a58478c0.zip
FreeBSD-src-cf0d26dcd6f3ae0595b32f615c52e365a58478c0.tar.gz
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.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/expand.c3
-rw-r--r--bin/sh/tests/parameters/positional8.031
2 files changed, 33 insertions, 1 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index f7c6735..6217982 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -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);
diff --git a/bin/sh/tests/parameters/positional8.0 b/bin/sh/tests/parameters/positional8.0
new file mode 100644
index 0000000..4c4dbd5
--- /dev/null
+++ b/bin/sh/tests/parameters/positional8.0
@@ -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
OpenPOWER on IntegriCloud