Date: Wed, 18 Nov 2015 21:09:03 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291025 - in head/bin/sh: . tests/parameters Message-ID: <201511182109.tAIL93n7062872@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Wed Nov 18 21:09:03 2015 New Revision: 291025 URL: https://svnweb.freebsd.org/changeset/base/291025 Log: 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. Added: head/bin/sh/tests/parameters/positional8.0 (contents, props changed) Modified: head/bin/sh/expand.c Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Wed Nov 18 18:11:19 2015 (r291024) +++ head/bin/sh/expand.c Wed Nov 18 21:09:03 2015 (r291025) @@ -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); Added: head/bin/sh/tests/parameters/positional8.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/parameters/positional8.0 Wed Nov 18 21:09:03 2015 (r291025) @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511182109.tAIL93n7062872>