ash: parser: Allow newlines within parameter substitution
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 11 Apr 2018 10:39:18 +0000 (12:39 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 11 Apr 2018 10:39:18 +0000 (12:39 +0200)
Upstream commit:

Date: Thu, 22 Mar 2018 21:41:24 +0800
parser: Allow newlines within parameter substitution

    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 <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-vars/param_expand_alt2.right [new file with mode: 0644]
shell/ash_test/ash-vars/param_expand_alt2.tests [new file with mode: 0755]
shell/hush_test/hush-vars/param_expand_alt2.right [new file with mode: 0644]
shell/hush_test/hush-vars/param_expand_alt2.tests [new file with mode: 0755]

index 6f8bc904287d2c845159ba147516f8b197d7e4d5..40ca82d0bd5f86ba65ab33c856d907b7b0d1a3b0 100644 (file)
@@ -11999,8 +11999,11 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
                CHECKSTRSPACE(4, out);  /* permit 4 calls to USTPUTC */
                switch (SIT(c, synstack->syntax)) {
                case CNL:       /* '\n' */
-                       if (synstack->syntax == BASESYNTAX)
+                       if (synstack->syntax == BASESYNTAX
+                        && !synstack->varnest
+                       ) {
                                goto endword;   /* exit outer loop */
+                       }
                        USTPUTC(c, out);
                        nlprompt();
                        c = pgetc();
diff --git a/shell/ash_test/ash-vars/param_expand_alt2.right b/shell/ash_test/ash-vars/param_expand_alt2.right
new file mode 100644 (file)
index 0000000..fef5889
--- /dev/null
@@ -0,0 +1,4 @@
+Unquoted: H H
+Quoted: H
+H
+Ok:0
diff --git a/shell/ash_test/ash-vars/param_expand_alt2.tests b/shell/ash_test/ash-vars/param_expand_alt2.tests
new file mode 100755 (executable)
index 0000000..d8abf4c
--- /dev/null
@@ -0,0 +1,7 @@
+echo Unquoted: H${$+
+}H
+
+echo Quoted: "H${$+
+}H"
+
+echo Ok:$?
diff --git a/shell/hush_test/hush-vars/param_expand_alt2.right b/shell/hush_test/hush-vars/param_expand_alt2.right
new file mode 100644 (file)
index 0000000..fef5889
--- /dev/null
@@ -0,0 +1,4 @@
+Unquoted: H H
+Quoted: H
+H
+Ok:0
diff --git a/shell/hush_test/hush-vars/param_expand_alt2.tests b/shell/hush_test/hush-vars/param_expand_alt2.tests
new file mode 100755 (executable)
index 0000000..d8abf4c
--- /dev/null
@@ -0,0 +1,7 @@
+echo Unquoted: H${$+
+}H
+
+echo Quoted: "H${$+
+}H"
+
+echo Ok:$?