On Wed, Sep 05, 2018 at 06:21:36PM +0200, Martijn Dekker wrote:
>
> With this patch applied, the following breakage still occurs:
> $ src/dash -u -c 'unset foo bar; echo ${foo+${bar}}'
> src/dash: 1: bar: parameter not set
> (expected: empty line, no error)
> ...which seems to suggest that ${bar} is evaluated even though foo is unset.
This patch should fix it.
---8<---
Subject: expand: Only call varunset when EXP_DISCARD is not set
When EXP_DISCARD is set, we must not generate a real error such
as varunset because we're only parsing the text and not evaluating
it.
For example:
$ dash -u -c 'unset foo bar; echo ${foo+${bar}}'
dash: 1: bar: parameter not set
This should not fail.
This patch fixes it by checking the EXP_DISCARD bit in the caller
flag before calling varunset.
Reported-by: Martijn Dekker <[email protected]>
Fixes: 3cd538634f71 ("expand: Do not reprocess data when...")
Signed-off-by: Herbert Xu <[email protected]>
diff --git a/src/expand.c b/src/expand.c
index e890052..d3e66c8 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -744,7 +744,7 @@ again:
goto again;
}
- if (discard && uflag)
+ if ((discard & ~flag) && uflag)
varunset(p, var, 0, 0);
if (subtype == VSLENGTH) {
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt