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:
parent
fa23ca22d3
commit
ee6bb75b10
@ -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++;
|
||||
|
@ -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>
|
||||
|
8
bin/sh/tests/expansion/plus-minus9.0
Normal file
8
bin/sh/tests/expansion/plus-minus9.0
Normal file
@ -0,0 +1,8 @@
|
||||
# $FreeBSD$
|
||||
|
||||
a=1
|
||||
b=${a+
|
||||
}
|
||||
n='
|
||||
'
|
||||
[ "$b" = "$n" ]
|
7
bin/sh/tests/expansion/trim10.0
Normal file
7
bin/sh/tests/expansion/trim10.0
Normal file
@ -0,0 +1,7 @@
|
||||
# $FreeBSD$
|
||||
|
||||
a='z
|
||||
'
|
||||
b=${a%
|
||||
}
|
||||
[ "$b" = z ]
|
7
bin/sh/tests/expansion/trim11.0
Normal file
7
bin/sh/tests/expansion/trim11.0
Normal file
@ -0,0 +1,7 @@
|
||||
# $FreeBSD$
|
||||
|
||||
a='z
|
||||
'
|
||||
b="${a%
|
||||
}"
|
||||
[ "$b" = z ]
|
Loading…
Reference in New Issue
Block a user