Skip to content

Commit

Permalink
sh: Allow empty << EOF markers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jillest committed Sep 2, 2015
1 parent 07e5aa0 commit 6633d3a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bin/sh/parser.c
Expand Up @@ -106,6 +106,8 @@ static int startlinno; /* line # where last token started */
static int funclinno; /* line # where the current function started */
static struct parser_temp *parser_temp;

#define NOEOFMARK ((const char *)&heredoclist)


static union node *list(int);
static union node *andor(void);
Expand Down Expand Up @@ -972,6 +974,10 @@ checkend(int c, const char *eofmark, int striptabs)
pungetc();
pushstring(eofmark + 1, q - (eofmark + 1), NULL);
}
} else if (c == '\n' && *eofmark == '\0') {
c = PEOF;
plinno++;
needprompt = doprompt;
}
return (c);
}
Expand Down Expand Up @@ -1383,7 +1389,7 @@ readtoken1(int firstc, char const *initialsyntax, const char *eofmark,

STARTSTACKSTR(out);
loop: { /* for each line, until end of word */
if (eofmark)
if (eofmark && eofmark != NOEOFMARK)
/* set c to PEOF if at end of here document */
c = checkend(c, eofmark, striptabs);
for (;;) { /* until end of line or end of word */
Expand Down Expand Up @@ -2046,7 +2052,7 @@ expandstr(const char *ps)
parser_temp = NULL;
setinputstring(ps, 1);
doprompt = 0;
readtoken1(pgetc(), DQSYNTAX, "", 0);
readtoken1(pgetc(), DQSYNTAX, NOEOFMARK, 0);
if (backquotelist != NULL)
error("Command substitution not allowed here");

Expand Down
1 change: 1 addition & 0 deletions bin/sh/tests/parser/Makefile
Expand Up @@ -57,6 +57,7 @@ FILES+= heredoc9.0
FILES+= heredoc10.0
FILES+= heredoc11.0
FILES+= heredoc12.0
FILES+= heredoc13.0
FILES+= line-cont1.0
FILES+= line-cont2.0
FILES+= line-cont3.0
Expand Down
21 changes: 21 additions & 0 deletions bin/sh/tests/parser/heredoc13.0
@@ -0,0 +1,21 @@
# $FreeBSD$

failures=0

check() {
if ! eval "[ $* ]"; then
echo "Failed: $*"
: $((failures += 1))
fi
}

check '"$(cat <<""

echo yes)" = "yes"'

check '"$(cat <<""
yes

)" = "yes"'

exit $((failures != 0))

0 comments on commit 6633d3a

Please sign in to comment.