From 298919f43a565cc2e130c8cb3f67773f7a54fca1 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 8 Nov 2022 14:12:01 +0000 Subject: [PATCH] users/28338: command substitution with alias edge case. See added regression test. --- ChangeLog | 5 +++++ Src/lex.c | 8 ++++++++ Test/D08cmdsubst.ztst | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7016ca76e..3018706b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-11-08 Peter Stephenson + + * users/28338: Src/lex.c, Test/D08cmdsubst.ztst: edge case of an + edge case in command expansion of alias. + 2022-11-06 Bart Schaefer * 50874: Src/jobs.c: fix handling of tty signals for jobs in diff --git a/Src/lex.c b/Src/lex.c index ece02659e..e2f8bcfb1 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1429,10 +1429,18 @@ gettokstr(int c, int sub) peek == STRING && lexbuf.ptr[-1] == '}' && lexbuf.ptr[-2] != Bnull) { /* hack to get {foo} command syntax work */ + /* + * Alias expansion when parsing command substitution means that + * the case for raw lexical analysis may not be the same. + * (Just go with it, OK?) + */ + int lar = lex_add_raw; + lex_add_raw = lexbuf_raw.len > 0 && lexbuf_raw.ptr[-1] == '}'; lexbuf.ptr--; lexbuf.len--; lexstop = 0; hungetc('}'); + lex_add_raw = lar; } *lexbuf.ptr = '\0'; DPUTS(cmdsp != ocmdsp, "BUG: gettok: cmdstack changed."); diff --git a/Test/D08cmdsubst.ztst b/Test/D08cmdsubst.ztst index 04bf698aa..e415831a0 100644 --- a/Test/D08cmdsubst.ztst +++ b/Test/D08cmdsubst.ztst @@ -177,3 +177,11 @@ 0:Alias expansion needed in parsing substitutions >hi >bye + +# This should silently print a blank line; the original problem was +# a parse error as the last character of the unexpanded alias +# was erased, symptom: "command not found: W" + alias WI='while {false}' + eval 'echo $(WI blah)' +0:Aliases with braces in command substitution can cause havoc +>