1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix single quotes in expansion operator string (re: 5ed9ffd6)

The referenced commit introduced the following bug:

> The closing quote does not appear to be registering during the
> parse of the following:
>
>	echo ${var:+'{}'}
>
> Within a script, this will result in:
>
>	syntax error at line 1: `'' unmatched

src/cmd/ksh93/data/lexstates.c,
src/cmd/ksh93/include/lexstates.h:
- Add new ST_MOD1 state table that is a copy of ST_QUOTE, but adds
  a special meaning (ST_LIT) for the single quote (position 39).

src/cmd/ksh93/sh/lex.c: sh_lex():
- For parameter expansion operators with old-style quoting
  (S_MOD1), use the new ST_MOD1 state table instead of ST_QUOTE.
  This causes single quotes within them to be processed properly.

src/cmd/ksh93/tests/quoting2.sh:
- Add tests.

Thanks to @gkamat for the bug report.
Resolves: https://github.com/ksh93/ksh/issues/290
This commit is contained in:
Martijn Dekker 2021-04-30 05:10:04 +01:00
parent 090b65e79b
commit d087b031f0
6 changed files with 47 additions and 4 deletions

View file

@ -387,6 +387,30 @@ static const char sh_lexstate9[256] =
0, 0, 0, S_BRACE,S_PAT, S_ENDCH,0, 0
};
/*
* ST_MOD1
* for skipping over a string S in ${v-S}, ${v+S}, ${v:-S}, ${v:+S}
*/
static const char sh_lexstate11[256] =
{
S_EOF, 0, 0, 0, 0, 0, 0, 0,
0, 0, S_NL, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, S_QUOTE,0, S_DOL, 0, 0, S_LIT,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, S_ESC, 0, 0, 0,
S_GRAVE,0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, S_RBRA, 0, 0
};
/*
* This must be kept synchronous with all the above and the ST_* definitions in lexstates.h
*/
@ -394,7 +418,7 @@ const char *sh_lexrstates[ST_NONE] =
{
sh_lexstate0, sh_lexstate1, sh_lexstate2, sh_lexstate3,
sh_lexstate4, sh_lexstate5, sh_lexstate6, sh_lexstate7,
sh_lexstate8, sh_lexstate9, sh_lexstate5
sh_lexstate8, sh_lexstate9, sh_lexstate5, sh_lexstate11
};