svn commit: r333927 - in head/bin/sh: . tests/expansion
Jilles Tjoelker
jilles at FreeBSD.org
Sun May 20 17:25:54 UTC 2018
Author: jilles
Date: Sun May 20 17:25:52 2018
New Revision: 333927
URL: https://svnweb.freebsd.org/changeset/base/333927
Log:
sh: Allow unquoted newlines in word in ${param+word} etc.
POSIX requires accepting unquoted newlines in word in parameter expansions
like ${param+word}, ${param#word}, although the Bourne shell did not support
it, it is not commonly used and might make it harder to find a missing
closing brace.
It was also strange that something like
foo="${bar#
}"
was rejected.
Reported by: Martijn Dekker via Robert Elz
Added:
head/bin/sh/tests/expansion/plus-minus9.0 (contents, props changed)
head/bin/sh/tests/expansion/trim10.0 (contents, props changed)
head/bin/sh/tests/expansion/trim11.0 (contents, props changed)
Modified:
head/bin/sh/parser.c
head/bin/sh/tests/expansion/Makefile
Modified: head/bin/sh/parser.c
==============================================================================
--- head/bin/sh/parser.c Sun May 20 16:03:21 2018 (r333926)
+++ head/bin/sh/parser.c Sun May 20 17:25:52 2018 (r333927)
@@ -1434,7 +1434,8 @@ readtoken1(int firstc, char const *initialsyntax, cons
switch(synentry) {
case CNL: /* '\n' */
- if (state[level].syntax == BASESYNTAX)
+ if (level == 0 &&
+ state[level].syntax == BASESYNTAX)
goto endword; /* exit outer loop */
USTPUTC(c, out);
plinno++;
Modified: head/bin/sh/tests/expansion/Makefile
==============================================================================
--- head/bin/sh/tests/expansion/Makefile Sun May 20 16:03:21 2018 (r333926)
+++ head/bin/sh/tests/expansion/Makefile Sun May 20 17:25:52 2018 (r333927)
@@ -84,6 +84,7 @@ ${PACKAGE}FILES+= plus-minus5.0
${PACKAGE}FILES+= plus-minus6.0
${PACKAGE}FILES+= plus-minus7.0
${PACKAGE}FILES+= plus-minus8.0
+${PACKAGE}FILES+= plus-minus9.0
${PACKAGE}FILES+= question1.0
${PACKAGE}FILES+= readonly1.0
${PACKAGE}FILES+= redir1.0
@@ -101,5 +102,7 @@ ${PACKAGE}FILES+= trim6.0
${PACKAGE}FILES+= trim7.0
${PACKAGE}FILES+= trim8.0
${PACKAGE}FILES+= trim9.0
+${PACKAGE}FILES+= trim10.0
+${PACKAGE}FILES+= trim11.0
.include <bsd.test.mk>
Added: head/bin/sh/tests/expansion/plus-minus9.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/plus-minus9.0 Sun May 20 17:25:52 2018 (r333927)
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+a=1
+b=${a+
+}
+n='
+'
+[ "$b" = "$n" ]
Added: head/bin/sh/tests/expansion/trim10.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/trim10.0 Sun May 20 17:25:52 2018 (r333927)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+a='z
+'
+b=${a%
+}
+[ "$b" = z ]
Added: head/bin/sh/tests/expansion/trim11.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/trim11.0 Sun May 20 17:25:52 2018 (r333927)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+a='z
+'
+b="${a%
+}"
+[ "$b" = z ]
More information about the svn-src-all
mailing list