1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-30 19:20:53 +02:00

35953: fix handling of command substitution in math context

This commit is contained in:
Barton E. Schaefer 2015-07-29 22:36:45 -07:00
parent 6fd8872d58
commit c0a80171ee
3 changed files with 16 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2015-07-29 Barton E. Schaefer <schaefer@zsh.org>
* 35953: Src/lex.c, Test/A01grammar.ztst: fix handling of command
substitution in math context, particularly in "for ((...))"
2015-07-28 Barton E. Schaefer <schaefer@zsh.org> 2015-07-28 Barton E. Schaefer <schaefer@zsh.org>
* 35947: Etc/zsh-development-guide: update discussion of module * 35947: Etc/zsh-development-guide: update discussion of module

View file

@ -1388,7 +1388,7 @@ dquote_parse(char endchar, int sub)
{ {
int pct = 0, brct = 0, bct = 0, intick = 0, err = 0; int pct = 0, brct = 0, bct = 0, intick = 0, err = 0;
int c; int c;
int math = endchar == ')' || endchar == ']'; int math = endchar == ')' || endchar == ']' || infor;
int zlemath = math && zlemetacs > zlemetall + addedx - inbufct; int zlemath = math && zlemetacs > zlemetall + addedx - inbufct;
while (((c = hgetc()) != endchar || bct || while (((c = hgetc()) != endchar || bct ||
@ -1995,8 +1995,10 @@ skipcomm(void)
#else #else
char *new_tokstr; char *new_tokstr;
int new_lexstop, new_lex_add_raw; int new_lexstop, new_lex_add_raw;
int save_infor = infor;
struct lexbufstate new_lexbuf; struct lexbufstate new_lexbuf;
infor = 0;
cmdpush(CS_CMDSUBST); cmdpush(CS_CMDSUBST);
SETPARBEGIN SETPARBEGIN
add(Inpar); add(Inpar);
@ -2065,6 +2067,7 @@ skipcomm(void)
* the recursive parsing. * the recursive parsing.
*/ */
lexflags &= ~LEXFLAGS_ZLE; lexflags &= ~LEXFLAGS_ZLE;
dbparens = 0; /* restored by zcontext_restore_partial() */
if (!parse_event(OUTPAR) || tok != OUTPAR) if (!parse_event(OUTPAR) || tok != OUTPAR)
lexstop = 1; lexstop = 1;
@ -2111,6 +2114,7 @@ skipcomm(void)
if (!lexstop) if (!lexstop)
SETPAREND SETPAREND
cmdpop(); cmdpop();
infor = save_infor;
return lexstop; return lexstop;
#endif #endif

View file

@ -182,6 +182,12 @@
>1 >1
>2 >2
for (( $(true); ; )); do break; done
for (( ; $(true); )); do break; done
for (( ; ; $(true) )); do break; done
for (( ; $((1)); )); do break; done
0:regression test, nested cmdsubst in arithmetic `for' loop
for keyvar valvar in key1 val1 key2 val2; do for keyvar valvar in key1 val1 key2 val2; do
print key=$keyvar val=$valvar print key=$keyvar val=$valvar
done done