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
This commit is contained in:
Jilles Tjoelker 2018-05-20 17:25:52 +00:00
parent 8dcd2ed3c9
commit 29988d0ef0
5 changed files with 27 additions and 1 deletions

View File

@ -1434,7 +1434,8 @@ readtoken1(int firstc, char const *initialsyntax, const char *eofmark,
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++;

View File

@ -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>

View File

@ -0,0 +1,8 @@
# $FreeBSD$
a=1
b=${a+
}
n='
'
[ "$b" = "$n" ]

View File

@ -0,0 +1,7 @@
# $FreeBSD$
a='z
'
b=${a%
}
[ "$b" = z ]

View File

@ -0,0 +1,7 @@
# $FreeBSD$
a='z
'
b="${a%
}"
[ "$b" = z ]