diff options
author | jilles <jilles@FreeBSD.org> | 2015-09-02 19:49:55 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-09-02 19:49:55 +0000 |
commit | 6633d3a788ab02ce8b43726487d2705bbad3ea29 (patch) | |
tree | 10068c99a4970e9a6a16045573916c3aa691ea81 /bin/sh | |
parent | 07e5aa0065f06f476317da8415d66994ec2d47e2 (diff) | |
download | FreeBSD-src-6633d3a788ab02ce8b43726487d2705bbad3ea29.zip FreeBSD-src-6633d3a788ab02ce8b43726487d2705bbad3ea29.tar.gz |
sh: Allow empty << EOF markers.
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/parser.c | 10 | ||||
-rw-r--r-- | bin/sh/tests/parser/Makefile | 1 | ||||
-rw-r--r-- | bin/sh/tests/parser/heredoc13.0 | 21 |
3 files changed, 30 insertions, 2 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 98b8791..302d179 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -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); @@ -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); } @@ -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 */ @@ -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"); diff --git a/bin/sh/tests/parser/Makefile b/bin/sh/tests/parser/Makefile index cbd2907..0d2ca0f 100644 --- a/bin/sh/tests/parser/Makefile +++ b/bin/sh/tests/parser/Makefile @@ -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 diff --git a/bin/sh/tests/parser/heredoc13.0 b/bin/sh/tests/parser/heredoc13.0 new file mode 100644 index 0000000..225d4f0 --- /dev/null +++ b/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)) |