sh: Fix heredoc at certain places in case and for
After an unescaped newline, there may be a here-document. Some places in case and for did not check for one. Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D32628
This commit is contained in:
parent
628c3b307f
commit
72f750dc7c
@ -480,9 +480,9 @@ command(void)
|
||||
n1 = (union node *)stalloc(sizeof (struct nfor));
|
||||
n1->type = NFOR;
|
||||
n1->nfor.var = wordtext;
|
||||
while (readtoken() == TNL)
|
||||
;
|
||||
if (lasttoken == TWORD && ! quoteflag && equal(wordtext, "in")) {
|
||||
checkkwd = CHKNL;
|
||||
if (readtoken() == TWORD && !quoteflag &&
|
||||
equal(wordtext, "in")) {
|
||||
app = ≈
|
||||
while (readtoken() == TWORD) {
|
||||
n2 = makename();
|
||||
@ -491,7 +491,9 @@ command(void)
|
||||
}
|
||||
*app = NULL;
|
||||
n1->nfor.args = ap;
|
||||
if (lasttoken != TNL && lasttoken != TSEMI)
|
||||
if (lasttoken == TNL)
|
||||
tokpushback++;
|
||||
else if (lasttoken != TSEMI)
|
||||
synexpect(-1);
|
||||
} else {
|
||||
static char argvars[5] = {
|
||||
@ -507,7 +509,7 @@ command(void)
|
||||
* Newline or semicolon here is optional (but note
|
||||
* that the original Bourne shell only allowed NL).
|
||||
*/
|
||||
if (lasttoken != TNL && lasttoken != TSEMI)
|
||||
if (lasttoken != TSEMI)
|
||||
tokpushback++;
|
||||
}
|
||||
checkkwd = CHKNL | CHKKWD | CHKALIAS;
|
||||
@ -526,8 +528,8 @@ command(void)
|
||||
n1->type = NCASE;
|
||||
consumetoken(TWORD);
|
||||
n1->ncase.expr = makename();
|
||||
while (readtoken() == TNL);
|
||||
if (lasttoken != TWORD || ! equal(wordtext, "in"))
|
||||
checkkwd = CHKNL;
|
||||
if (readtoken() != TWORD || ! equal(wordtext, "in"))
|
||||
synerror("expecting \"in\"");
|
||||
cpp = &n1->ncase.cases;
|
||||
checkkwd = CHKNL | CHKKWD, readtoken();
|
||||
|
@ -65,6 +65,9 @@ ${PACKAGE}FILES+= heredoc10.0
|
||||
${PACKAGE}FILES+= heredoc11.0
|
||||
${PACKAGE}FILES+= heredoc12.0
|
||||
${PACKAGE}FILES+= heredoc13.0
|
||||
${PACKAGE}FILES+= heredoc14.0
|
||||
${PACKAGE}FILES+= heredoc15.0
|
||||
${PACKAGE}FILES+= heredoc16.0
|
||||
${PACKAGE}FILES+= line-cont1.0
|
||||
${PACKAGE}FILES+= line-cont2.0
|
||||
${PACKAGE}FILES+= line-cont3.0
|
||||
|
8
bin/sh/tests/parser/heredoc14.0
Normal file
8
bin/sh/tests/parser/heredoc14.0
Normal file
@ -0,0 +1,8 @@
|
||||
#
|
||||
read x <<EOF; for i in "$x"
|
||||
value
|
||||
EOF
|
||||
do
|
||||
x=$x.$i
|
||||
done
|
||||
[ "$x" = value.value ]
|
9
bin/sh/tests/parser/heredoc15.0
Normal file
9
bin/sh/tests/parser/heredoc15.0
Normal file
@ -0,0 +1,9 @@
|
||||
#
|
||||
set -- dummy
|
||||
read x <<EOF; for i
|
||||
value
|
||||
EOF
|
||||
do
|
||||
x=$x.$i
|
||||
done
|
||||
[ "$x" = value.dummy ]
|
8
bin/sh/tests/parser/heredoc16.0
Normal file
8
bin/sh/tests/parser/heredoc16.0
Normal file
@ -0,0 +1,8 @@
|
||||
#
|
||||
read x <<EOF; case $x
|
||||
value
|
||||
EOF
|
||||
in
|
||||
value) x=$x.extended
|
||||
esac
|
||||
[ "$x" = value.extended ]
|
Loading…
Reference in New Issue
Block a user