From e34ce85151dcd5ac698e116a6742d481ff64ae2c Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Sun, 18 Jan 2015 16:43:26 +0000
Subject: 34319: fix alias expansion in history for command substitution
---
Src/hist.c | 26 ++++++++++++++++++++------
Src/lex.c | 2 +-
2 files changed, 21 insertions(+), 7 deletions(-)
(limited to 'Src')
diff --git a/Src/hist.c b/Src/hist.c
index e5c48dbc1..11d9722d5 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -329,7 +329,16 @@ static void
ihwaddc(int c)
{
/* Only if history line exists and lexing has not finished. */
- if (chline && !(errflag || lexstop)) {
+ if (chline && !(errflag || lexstop) &&
+ /*
+ * If we're reading inside a word for command substitution
+ * we allow the lexer to expand aliases but don't deal
+ * with them here. Note matching code in ihungetc().
+ * TBD: it might be neater to deal with all aliases in this
+ * fashion as we never need the expansion in the history
+ * line, only in the lexer and above.
+ */
+ !((histactive & HA_INWORD) && (inbufflags & INP_ALIAS))) {
/* Quote un-expanded bangs in the history line. */
if (c == bangchar && stophist < 2 && qbang)
/* If qbang is not set, we do not escape this bangchar as it's *
@@ -892,11 +901,16 @@ ihungetc(int c)
zlemetall--;
exlast++;
}
- DPUTS(hptr <= chline, "BUG: hungetc attempted at buffer start");
- hptr--;
- DPUTS(*hptr != (char) c, "BUG: wrong character in hungetc() ");
- qbang = (c == bangchar && stophist < 2 &&
- hptr > chline && hptr[-1] == '\\');
+ if (!(histactive & HA_INWORD) || !(inbufflags & INP_ALIAS)) {
+ DPUTS(hptr <= chline, "BUG: hungetc attempted at buffer start");
+ hptr--;
+ DPUTS(*hptr != (char) c, "BUG: wrong character in hungetc() ");
+ qbang = (c == bangchar && stophist < 2 &&
+ hptr > chline && hptr[-1] == '\\');
+ } else {
+ /* No active bangs in aliases */
+ qbang = 0;
+ }
if (doit)
inungetc(c);
if (!qbang)
diff --git a/Src/lex.c b/Src/lex.c
index 6d45c70c7..e4dfdfaca 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1674,7 +1674,7 @@ parse_subst_string(char *s)
/* Called below to report word positions. */
/**/
-mod_export void
+static void
gotword(void)
{
we = zlemetall + 1 - inbufct + (addedx == 2 ? 1 : 0);
--
cgit 1.4.1