Skip to content

Commit

Permalink
Fix regression caused by ${var:-'{}'} fix (re: f31e368)
Browse files Browse the repository at this point in the history
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 ${var<OP>string} 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.
  • Loading branch information
McDutchie committed May 3, 2021
1 parent af6a32d commit 5ed4c71
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cmd/ksh93/sh/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,12 @@ static int varsub(Mac_t *mp)
}
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);
Expand Down

0 comments on commit 5ed4c71

Please sign in to comment.