From 5ed4c71fca25b3b035561c3cefeb8109839c35e9 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 3 May 2021 05:55:47 +0100 Subject: [PATCH] Fix regression caused by ${var:-'{}'} fix (re: f31e3687) The regression is: quoting.sh[189]: expansion of "{q:+'}" not correct when q unset The failure was that, for unset q, "${q:+'}q${q:+'}" yielded empty and not 'q'. This is because the single quotes within the double quotes were erroneously parsed as meaningful. The originally used ST_QUOTE state table (see data/lexstates.c), where no quote character has any special meaning, was for avoiding this problem. The newly introduced ST_MOD1 state table is a copy of ST_QUOTE except the ' has been given its special meaning back. We need this to fix #290, but only for unquoted expansions. So we need to go back to using ST_QUOTE if the string is quoted (mp->quote) and we're not parsing a substitution that uses patterns where quotes are significant (newops, ST_MOD2), i.e., only for old-style ST_MOD1 operators. src/cmd/ksh93/sh/macro.c: varsub(): - When the ${varstring} expansion is quoted, and of an old (S_MOD1) type, then use the ST_QUOTE state table to skip over it instead of the new ST_MOD1 one. --- src/cmd/ksh93/sh/macro.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index 254451800..5e33ce458 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -1659,7 +1659,12 @@ retry1: } else { - sh_lexskip(lp, RBRACE, 0, sh_lexstates[ST_BRACE][c]==S_MOD1 ? ST_MOD1 : ST_NESTED); + int state; + if(sh_lexstates[ST_BRACE][c]==S_MOD1) + state = mp->quote ? ST_QUOTE : ST_MOD1; + else + state = ST_NESTED; + sh_lexskip(lp, RBRACE, 0, state); stkseek(stkp,offset); } argp=stkptr(stkp,offset);