1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-17 00:31:09 +02:00

35668: Improved fix for command/proc subst starting in alias.

Use input flag to suppress the unwanted backtracking.

Add test for the extra case covered.
This commit is contained in:
Peter Stephenson 2015-07-02 10:01:42 +01:00
parent dce1f33c02
commit 2afdb3985a
5 changed files with 30 additions and 12 deletions

View file

@ -1,3 +1,10 @@
2015-07-02 Peter Stephenson <p.stephenson@samsung.com>
* 35668: Src/input.c, Src/lex.c, Src/zsh.h,
Test/D03procsubst.ztst: replacement for 35667:
use input flag to stop unwanted backtracking,
additional test.
2015-07-01 Peter Stephenson <p.w.stephenson@ntlworld.com> 2015-07-01 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 35667: Src/lex.c, Src/zsh.h, Test/D03procsubst.ztst, * 35667: Src/lex.c, Src/zsh.h, Test/D03procsubst.ztst,

View file

@ -591,7 +591,7 @@ inpoptop(void)
* history is before, but they're both pushed onto * history is before, but they're both pushed onto
* the input stack. * the input stack.
*/ */
if ((inbufflags & (INP_ALIAS|INP_HIST)) == INP_ALIAS) if ((inbufflags & (INP_ALIAS|INP_HIST|INP_RAW_KEEP)) == INP_ALIAS)
zshlex_raw_back(); zshlex_raw_back();
} }
} }

View file

@ -162,7 +162,7 @@ static int lex_add_raw;
/* variables associated with the above */ /* variables associated with the above */
static char *tokstr_raw, *lexbuf_ptr_start; static char *tokstr_raw;
static struct lexbufstate lexbuf_raw; static struct lexbufstate lexbuf_raw;
/* text of punctuation tokens */ /* text of punctuation tokens */
@ -229,13 +229,12 @@ lex_context_save(struct lex_stack *ls, int toplevel)
ls->lex_add_raw = lex_add_raw; ls->lex_add_raw = lex_add_raw;
ls->tokstr_raw = tokstr_raw; ls->tokstr_raw = tokstr_raw;
ls->lexbuf_raw = lexbuf_raw; ls->lexbuf_raw = lexbuf_raw;
ls->lexbuf_ptr_start = lexbuf_ptr_start;
ls->lexstop = lexstop; ls->lexstop = lexstop;
ls->toklineno = toklineno; ls->toklineno = toklineno;
tokstr = zshlextext = lexbuf.ptr = NULL; tokstr = zshlextext = lexbuf.ptr = NULL;
lexbuf.siz = 256; lexbuf.siz = 256;
tokstr_raw = lexbuf_raw.ptr = lexbuf_ptr_start = NULL; tokstr_raw = lexbuf_raw.ptr = NULL;
lexbuf_raw.siz = lexbuf_raw.len = lex_add_raw = 0; lexbuf_raw.siz = lexbuf_raw.len = lex_add_raw = 0;
} }
@ -258,7 +257,6 @@ lex_context_restore(const struct lex_stack *ls, int toplevel)
lex_add_raw = ls->lex_add_raw; lex_add_raw = ls->lex_add_raw;
tokstr_raw = ls->tokstr_raw; tokstr_raw = ls->tokstr_raw;
lexbuf_raw = ls->lexbuf_raw; lexbuf_raw = ls->lexbuf_raw;
lexbuf_ptr_start = ls->lexbuf_ptr_start;
lexstop = ls->lexstop; lexstop = ls->lexstop;
toklineno = ls->toklineno; toklineno = ls->toklineno;
} }
@ -1884,7 +1882,7 @@ zshlex_raw_add(int c)
void void
zshlex_raw_back(void) zshlex_raw_back(void)
{ {
if (!lex_add_raw || lexbuf_raw.ptr == lexbuf_ptr_start) if (!lex_add_raw)
return; return;
lexbuf_raw.ptr--; lexbuf_raw.ptr--;
lexbuf_raw.len--; lexbuf_raw.len--;
@ -1995,7 +1993,7 @@ skipcomm(void)
cmdpop(); cmdpop();
return lexstop; return lexstop;
#else #else
char *new_tokstr, *new_lexbuf_ptr_start; char *new_tokstr;
int new_lexstop, new_lex_add_raw; int new_lexstop, new_lex_add_raw;
struct lexbufstate new_lexbuf; struct lexbufstate new_lexbuf;
@ -2023,6 +2021,18 @@ skipcomm(void)
new_tokstr = tokstr; new_tokstr = tokstr;
new_lexbuf = lexbuf; new_lexbuf = lexbuf;
/*
* If we're expanding an alias at this point, we need the whole
* remaining text as part of the string for the command in
* parentheses, so don't backtrack. This is different from the
* usual case where the alias is fully within the command, where
* we want the unexpanded text so that it will be expanded
* again when the command in the parentheses is executed.
*
* I never wanted to be a software engineer, you know.
*/
if (inbufflags & INP_ALIAS)
inbufflags |= INP_RAW_KEEP;
zcontext_save_partial(ZCONTEXT_LEX|ZCONTEXT_PARSE); zcontext_save_partial(ZCONTEXT_LEX|ZCONTEXT_PARSE);
hist_in_word(1); hist_in_word(1);
} else { } else {
@ -2042,7 +2052,6 @@ skipcomm(void)
} }
tokstr_raw = new_tokstr; tokstr_raw = new_tokstr;
lexbuf_raw = new_lexbuf; lexbuf_raw = new_lexbuf;
lexbuf_ptr_start = lexbuf_raw.ptr;
lex_add_raw = new_lex_add_raw; lex_add_raw = new_lex_add_raw;
/* /*
* Don't do any ZLE specials down here: they're only needed * Don't do any ZLE specials down here: they're only needed
@ -2067,7 +2076,6 @@ skipcomm(void)
*/ */
new_tokstr = tokstr_raw; new_tokstr = tokstr_raw;
new_lexbuf = lexbuf_raw; new_lexbuf = lexbuf_raw;
new_lexbuf_ptr_start = lexbuf_ptr_start;
/* /*
* We're also going to propagate the lexical state: * We're also going to propagate the lexical state:
* if we couldn't parse the command substitution we * if we couldn't parse the command substitution we
@ -2083,7 +2091,6 @@ skipcomm(void)
*/ */
tokstr_raw = new_tokstr; tokstr_raw = new_tokstr;
lexbuf_raw = new_lexbuf; lexbuf_raw = new_lexbuf;
lexbuf_ptr_start = new_lexbuf_ptr_start;
} else { } else {
if (!new_lexstop) { if (!new_lexstop) {
/* Ignore the ')' added on input */ /* Ignore the ')' added on input */
@ -2098,7 +2105,6 @@ skipcomm(void)
tokstr = new_tokstr; tokstr = new_tokstr;
lexbuf = new_lexbuf; lexbuf = new_lexbuf;
lexstop = new_lexstop; lexstop = new_lexstop;
lexbuf_ptr_start = (char *)NULL;
hist_in_word(0); hist_in_word(0);
} }

View file

@ -425,6 +425,7 @@ enum {
#define INP_HISTCONT (1<<5) /* stack is continued from history expn. */ #define INP_HISTCONT (1<<5) /* stack is continued from history expn. */
#define INP_LINENO (1<<6) /* update line number */ #define INP_LINENO (1<<6) /* update line number */
#define INP_APPEND (1<<7) /* Append new lines to allow backup */ #define INP_APPEND (1<<7) /* Append new lines to allow backup */
#define INP_RAW_KEEP (1<<8) /* Input needed in raw mode even if alias */
/* Flags for metafy */ /* Flags for metafy */
#define META_REALLOC 0 #define META_REALLOC 0
@ -2801,7 +2802,6 @@ struct lex_stack {
int lex_add_raw; int lex_add_raw;
char *tokstr_raw; char *tokstr_raw;
struct lexbufstate lexbuf_raw; struct lexbufstate lexbuf_raw;
char *lexbuf_ptr_start;
int lexstop; int lexstop;
zlong toklineno; zlong toklineno;
}; };

View file

@ -121,3 +121,8 @@
eval 'foo echo this is bound to work)' eval 'foo echo this is bound to work)'
0:backtacking within command string parsing with alias still pending 0:backtacking within command string parsing with alias still pending
>this is bound to work >this is bound to work
alias foo='cat <( print'
eval 'foo here is some output)'
0:full alias expanded when substitution starts in alias
>here is some output