From patchwork Thu Mar 22 13:41:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10301551 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C699760216 for ; Thu, 22 Mar 2018 13:43:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B17142844C for ; Thu, 22 Mar 2018 13:43:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEC8028459; Thu, 22 Mar 2018 13:43:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C029E285E4 for ; Thu, 22 Mar 2018 13:41:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752339AbeCVNli (ORCPT ); Thu, 22 Mar 2018 09:41:38 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:56776 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753313AbeCVNlh (ORCPT ); Thu, 22 Mar 2018 09:41:37 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtp (Exim 4.84_2 #2 (Debian)) id 1ez0T9-0003C5-Lu; Thu, 22 Mar 2018 21:41:27 +0800 Received: from herbert by gondobar with local (Exim 4.84_2) (envelope-from ) id 1ez0T6-0007Fw-83; Thu, 22 Mar 2018 21:41:24 +0800 Date: Thu, 22 Mar 2018 21:41:24 +0800 From: Herbert Xu To: Harald van Dijk Cc: martijn@inlv.org, dash@vger.kernel.org Subject: parser: Allow newlines within parameter substitution Message-ID: <20180322134124.GA27851@gondor.apana.org.au> References: <20180315102730.GA32076@gondor.apana.org.au> <26f1f670-233c-ed9f-0f5e-6302aa4bcd79@gigawatt.nl> <20180315145215.GC31069@gondor.apana.org.au> <20180315171108.GA1575@gondor.apana.org.au> <55a884a1-d6da-8466-87a9-dbf9ce0740ed@gigawatt.nl> <20180316032722.GB3034@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180316032722.GB3034@gondor.apana.org.au> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote: > On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote: > > > > Okay, it can be trivially modified to something that does work in other > > shells (even if it were actually executed), but gets rejected at parse time > > by dash: > > > > if false; then > > : ${$+ > > } > > fi > > That's just a bug in dash's parser with ${} in general, because > it bombs out without the if clause too: > > : ${$+ > } This patch fixes the parsing of newlines with parameter substitution. Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index ae76400..6a8a4a4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -924,7 +924,8 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs) CHECKSTRSPACE(4, out); /* permit 4 calls to USTPUTC */ switch(synstack->syntax[c]) { case CNL: /* '\n' */ - if (synstack->syntax == BASESYNTAX) + if (synstack->syntax == BASESYNTAX && + !synstack->varnest) goto endword; /* exit outer loop */ USTPUTC(c, out); nlprompt();