From owner-svn-src-all@freebsd.org Wed Sep 2 19:49:57 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 672099C8F50; Wed, 2 Sep 2015 19:49:57 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3E95A9FE; Wed, 2 Sep 2015 19:49:57 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t82Jnviw095155; Wed, 2 Sep 2015 19:49:57 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t82JnuDi095151; Wed, 2 Sep 2015 19:49:56 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201509021949.t82JnuDi095151@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Wed, 2 Sep 2015 19:49:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287408 - in head/bin/sh: . tests/parser X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Sep 2015 19:49:57 -0000 Author: jilles Date: Wed Sep 2 19:49:55 2015 New Revision: 287408 URL: https://svnweb.freebsd.org/changeset/base/287408 Log: sh: Allow empty << EOF markers. Added: head/bin/sh/tests/parser/heredoc13.0 (contents, props changed) Modified: head/bin/sh/parser.c head/bin/sh/tests/parser/Makefile Modified: head/bin/sh/parser.c ============================================================================== --- head/bin/sh/parser.c Wed Sep 2 18:51:36 2015 (r287407) +++ head/bin/sh/parser.c Wed Sep 2 19:49:55 2015 (r287408) @@ -106,6 +106,8 @@ static int startlinno; /* line # where 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 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 *initi 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"); Modified: head/bin/sh/tests/parser/Makefile ============================================================================== --- head/bin/sh/tests/parser/Makefile Wed Sep 2 18:51:36 2015 (r287407) +++ head/bin/sh/tests/parser/Makefile Wed Sep 2 19:49:55 2015 (r287408) @@ -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 Added: head/bin/sh/tests/parser/heredoc13.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/parser/heredoc13.0 Wed Sep 2 19:49:55 2015 (r287408) @@ -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))