reopen 418774
quit

On Fri, Oct 05, 2007 at 07:36:47AM -0400, Paul Smith wrote:
>
> > /bin/sh -c 'if false; then d="${foo/bar}"; fi'
> 
> Note the "if false;...".  The POSIX spec, in the sections we have quoted
> above, is clear that this should NOT be an error, because that reference
> is never expanded.

Fair enough.  I've fixed it as follows.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
3df3edd13389ae768010bfacee5612346b413e38
diff --git a/ChangeLog b/ChangeLog
index 1db14ac..69ba464 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-10-08  Herbert Xu <[EMAIL PROTECTED]>
+
+       * Report substition errors at expansion time.
+
 2007-10-06  Herbert Xu <[EMAIL PROTECTED]>
 
        * Add pushstackmark.
diff --git a/src/expand.c b/src/expand.c
index e3e5d8f..54fe908 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -749,6 +749,10 @@ evalvar(char *p, int flag)
 
        varflags = *p++;
        subtype = varflags & VSTYPE;
+
+       if (!subtype)
+               sh_error("Bad substitution");
+
        quoted = flag & EXP_QUOTED;
        var = p;
        easy = (!quoted || (*var == '@' && shellparam.nparam));
diff --git a/src/parser.c b/src/parser.c
index d0e0553..4b8a5fe 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1204,9 +1204,8 @@ varname:
                        USTPUTC(cc, out);
                }
                else
-badsub:                        synerror("Bad substitution");
+                       goto badsub;
 
-               STPUTC('=', out);
                if (subtype == 0) {
                        switch (c) {
                        case ':':
@@ -1216,7 +1215,7 @@ badsub:                   synerror("Bad substitution");
                        default:
                                p = strchr(types, c);
                                if (p == NULL)
-                                       goto badsub;
+                                       break;
                                subtype |= p - types + VSNORMAL;
                                break;
                        case '%':
@@ -1234,6 +1233,7 @@ badsub:                   synerror("Bad substitution");
                                }
                        }
                } else {
+badsub:
                        pungetc();
                }
                *((char *)stackblock() + typeloc) = subtype;
@@ -1242,6 +1242,7 @@ badsub:                   synerror("Bad substitution");
                        if (dblquote)
                                dqvarnest++;
                }
+               STPUTC('=', out);
        }
        goto parsesub_return;
 }



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to