Hi all,
I've attempted to write a patch fixing an issue mentioned here
http://lists.gnu.org/archive/html/bug-bash/2012-02/msg00106.html a while
back. It basically wraps parameter expansion around a new context of
it's own, using it to make another condition for single-quote
substitution. While it's by no means perfect, it makes parameter
expansion a bit more sane IMHO. The change should eventually have a new
compat option, since it breaks a few test cases (I suppose making it
fully backwards-compatible is impossible). I'd really appreciate some
comments and advice on the patch's approach and/or necessary improvements.
Thanks,
Ondrej
>From 3ac7b13686ad4ea477f12bfba759f14e2d05062a Mon Sep 17 00:00:00 2001
From: Ondrej Oprala <oopr...@redhat.com>
Date: Thu, 1 Nov 2012 14:39:27 +0100
Subject: [PATCH] Bash-4.2 patch 40
---
subst.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/subst.c b/subst.c
index 937c71d..7010dae 100644
--- a/subst.c
+++ b/subst.c
@@ -7933,6 +7933,8 @@ expand_word_internal (word, quoted, isexp,
contains_dollar_at, expanded_somethin
char twochars[2];
+ static int p_exp; /* parameter expansion context. */
+
DECLARE_MBSTATE;
istring = (char *)xmalloc (istring_size = DEFAULT_INITIAL_ARRAY_SIZE);
@@ -8131,9 +8133,12 @@ add_string:
pflags = (word->flags & W_NOCOMSUB) ? PF_NOCOMSUB : 0;
if (word->flags & W_NOSPLIT2)
pflags |= PF_NOSPLIT2;
+ p_exp = 1;
tword = param_expand (string, &sindex, quoted, expanded_something,
&temp_has_dollar_at, "ed_dollar_at,
&had_quoted_null, pflags);
+ if (!string[sindex])
+ p_exp = 0;
has_dollar_at += temp_has_dollar_at;
if (tword == &expand_wdesc_error || tword == &expand_wdesc_fatal)
@@ -8225,7 +8230,8 @@ add_string:
{
SCOPY_CHAR_I (twochars, CTLESC, c, string, sindex, string_size);
}
- else if ((quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) &&
((sh_syntaxtab[c] & tflag) == 0))
+ else if ((quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) &&
((sh_syntaxtab[c] & tflag) == 0) &&
+ !(c == '\'' && p_exp))
{
SCOPY_CHAR_I (twochars, '\\', c, string, sindex, string_size);
}
--
1.7.11.7