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:
parent
090b65e79b
commit
d087b031f0
6 changed files with 47 additions and 4 deletions
5
NEWS
5
NEWS
|
@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
||||||
|
|
||||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
|
|
||||||
|
2021-04-30:
|
||||||
|
|
||||||
|
- Fixed a bug introduced on 2020-09-05 that caused "echo ${var:+'{}'}"
|
||||||
|
to be misparsed.
|
||||||
|
|
||||||
2021-04-26:
|
2021-04-26:
|
||||||
|
|
||||||
- Fixed a bug introduced on 2021-02-20 in which a shared-state command
|
- Fixed a bug introduced on 2021-02-20 in which a shared-state command
|
||||||
|
|
|
@ -387,6 +387,30 @@ static const char sh_lexstate9[256] =
|
||||||
0, 0, 0, S_BRACE,S_PAT, S_ENDCH,0, 0
|
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
|
* 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_lexstate0, sh_lexstate1, sh_lexstate2, sh_lexstate3,
|
||||||
sh_lexstate4, sh_lexstate5, sh_lexstate6, sh_lexstate7,
|
sh_lexstate4, sh_lexstate5, sh_lexstate6, sh_lexstate7,
|
||||||
sh_lexstate8, sh_lexstate9, sh_lexstate5
|
sh_lexstate8, sh_lexstate9, sh_lexstate5, sh_lexstate11
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,8 @@
|
||||||
#define ST_DOLNAME 8
|
#define ST_DOLNAME 8
|
||||||
#define ST_MACRO 9
|
#define ST_MACRO 9
|
||||||
#define ST_QNEST 10
|
#define ST_QNEST 10
|
||||||
#define ST_NONE 11
|
#define ST_MOD1 11
|
||||||
|
#define ST_NONE 12
|
||||||
|
|
||||||
#include "FEATURE/locale"
|
#include "FEATURE/locale"
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
||||||
#define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */
|
#define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */
|
||||||
#define SH_RELEASE_DATE "2021-04-26" /* must be in this format for $((.sh.version)) */
|
#define SH_RELEASE_DATE "2021-04-30" /* must be in this format for $((.sh.version)) */
|
||||||
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
|
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
|
||||||
|
|
||||||
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
||||||
|
|
|
@ -992,7 +992,7 @@ int sh_lex(Lex_t* lp)
|
||||||
mode = ST_NESTED;
|
mode = ST_NESTED;
|
||||||
continue;
|
continue;
|
||||||
case S_MOD1:
|
case S_MOD1:
|
||||||
mode = ST_QUOTE;
|
mode = ST_MOD1;
|
||||||
continue;
|
continue;
|
||||||
case S_MOD2:
|
case S_MOD2:
|
||||||
#if SHOPT_KIA
|
#if SHOPT_KIA
|
||||||
|
|
|
@ -250,5 +250,18 @@ actual=$(printf %q $'1\x[11]1')
|
||||||
[[ $actual == "$expect" ]] || err_exit 'shell-quoting: hex bytes not protected from subsequent hex-like chars' \
|
[[ $actual == "$expect" ]] || err_exit 'shell-quoting: hex bytes not protected from subsequent hex-like chars' \
|
||||||
"(expected $expect; got $actual)"
|
"(expected $expect; got $actual)"
|
||||||
|
|
||||||
|
# ======
|
||||||
|
# https://github.com/ksh93/ksh/issues/290
|
||||||
|
var=dummy
|
||||||
|
exp='{}'
|
||||||
|
got=$(eval 'echo ${var:+'\''{}'\''}' 2>&1)
|
||||||
|
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (1)" \
|
||||||
|
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||||
|
unset var
|
||||||
|
exp='}'
|
||||||
|
got=$(eval 'echo ${var:-'\''}'\''}' 2>&1)
|
||||||
|
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (2)" \
|
||||||
|
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue