1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

Fix lexing of 'case' in do...done in a $(comsub) (rhbz#1241013)

The following caused a spurious syntax error:

$ x=$(for i in 1; do case $i in word) true;; esac; done)
-ksh: syntax error: `;;' unexpected

Prior discussion:
https://bugzilla.redhat.com/1241013

Original patch, backported from 93v- beta, applied without change:
https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-parserfix.patch
This commit is contained in:
Martijn Dekker 2020-09-27 21:26:09 +02:00
parent bb15f7fb19
commit bd283959be
4 changed files with 27 additions and 1 deletions

9
NEWS
View file

@ -3,6 +3,15 @@ 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.
2020-09-27:
- The shell's lexical analisys of a 'case' statement within a do...done block
within a command substitution of the form $(...) has been fixed so that code
like the following no longer throws a spurious syntax error:
x=$(for i in 1; do case $i in word) true;; esac; done)
Previously, this required a leading parenthesis before 'word', although the
syntax error claimed that the ';;' was unexpected.
2020-09-26: 2020-09-26:
- 'whence -f' now completely ignores the existence of functions, as documented. - 'whence -f' now completely ignores the existence of functions, as documented.

View file

@ -17,4 +17,4 @@
* David Korn <dgk@research.att.com> * * David Korn <dgk@research.att.com> *
* * * *
***********************************************************************/ ***********************************************************************/
#define SH_RELEASE "93u+m 2020-09-26" #define SH_RELEASE "93u+m 2020-09-27"

View file

@ -1541,6 +1541,7 @@ breakloop:
/* /*
* read to end of command substitution * read to end of command substitution
* of the form $(...)
*/ */
static int comsub(register Lex_t *lp, int endtok) static int comsub(register Lex_t *lp, int endtok)
{ {
@ -1593,7 +1594,14 @@ static int comsub(register Lex_t *lp, int endtok)
if(n==4) if(n==4)
break; break;
if(sh_lexstates[ST_NAME][c]) if(sh_lexstates[ST_NAME][c])
{
if(c==' ' || c=='\t')
{
n = 0;
continue;
}
goto skip; goto skip;
}
word[n++] = c; word[n++] = c;
} }
if(sh_lexstates[ST_NAME][c]==S_BREAK) if(sh_lexstates[ST_NAME][c]==S_BREAK)

View file

@ -716,5 +716,14 @@ else err_exit "warning: skipping argv rewrite test due to noncompliant 'ps' util
let Errors-- let Errors--
fi fi
# ======
# https://bugzilla.redhat.com/1241013
got=$(eval 'x=$(for i in test; do case $i in test) true;; esac; done)' 2>&1) \
|| err_exit "case in a for loop inside a \$(comsub) caused syntax error (got $(printf %q "$got"))"
got=$(eval 'x=${ for i in test; do case $i in test) true;; esac; done; }' 2>&1) \
|| err_exit "case in a for loop inside a \${ comsub; } caused syntax error (got $(printf %q "$got"))"
got=$(eval 'x=`for i in test; do case $i in test) true;; esac; done`' 2>&1) \
|| err_exit "case in a for loop inside a \`comsub\` caused syntax error (got $(printf %q "$got"))"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))