diff options
Diffstat (limited to 'y.tab.c')
-rw-r--r-- | y.tab.c | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -6374,10 +6374,11 @@ parse_comsub (qc, open, close, lenp, flags) int *lenp, flags; { int peekc, r; - int start_lineno; + int start_lineno, local_extglob, was_extpat; char *ret, *tcmd; int retlen; sh_parser_state_t ps; + STRING_SAVER *saved_strings; COMMAND *saved_global, *parsed_command; /* Posix interp 217 says arithmetic expressions have precedence, so @@ -6397,7 +6398,7 @@ parse_comsub (qc, open, close, lenp, flags) save_parser_state (&ps); - pushed_string_list = (STRING_SAVER *)NULL; + was_extpat = (parser_state & PST_EXTPAT); /* State flags we don't want to persist into command substitutions. */ parser_state &= ~(PST_REGEXP|PST_EXTPAT|PST_CONDCMD|PST_CONDEXPR|PST_COMPASSIGN); @@ -6409,6 +6410,8 @@ parse_comsub (qc, open, close, lenp, flags) /* State flags we want to set for this run through the parser. */ parser_state |= PST_CMDSUBST|PST_EOFTOKEN|PST_NOEXPAND; + /* leave pushed_string_list alone, since we might need to consume characters + from it to satisfy this command substitution (in some perverse case). */ shell_eof_token = close; saved_global = global_command; /* might not be necessary */ @@ -6425,9 +6428,13 @@ parse_comsub (qc, open, close, lenp, flags) if (expand_aliases) expand_aliases = posixly_correct != 0; #if defined (EXTENDED_GLOB) - global_extglob = extended_glob; - if (shell_compatibility_level <= 51) - extended_glob = 1; + /* If (parser_state & PST_EXTPAT), we're parsing an extended pattern for a + conditional command and have already set global_extglob appropriately. */ + if (shell_compatibility_level <= 51 && was_extpat == 0) + { + local_extglob = global_extglob = extended_glob; + extended_glob = 1; + } #endif current_token = '\n'; /* XXX */ @@ -6442,7 +6449,8 @@ parse_comsub (qc, open, close, lenp, flags) } #if defined (EXTENDED_GLOB) - extended_glob = global_extglob; + if (shell_compatibility_level <= 51 && was_extpat == 0) + extended_glob = local_extglob; #endif parsed_command = global_command; @@ -6469,7 +6477,7 @@ parse_comsub (qc, open, close, lenp, flags) shell_eof_token = ps.eof_token; expand_aliases = ps.expand_aliases; - jump_to_top_level (DISCARD); + jump_to_top_level (DISCARD); /* XXX - return (&matched_pair_error)? */ } } @@ -6488,7 +6496,12 @@ INTERNAL_DEBUG(("current_token (%d) != shell_eof_token (%c)", current_token, she return (&matched_pair_error); } + /* We don't want to restore the old pushed string list, since we might have + used it to consume additional input from an alias while parsing this + command substitution. */ + saved_strings = pushed_string_list; restore_parser_state (&ps); + pushed_string_list = saved_strings; tcmd = print_comsub (parsed_command); /* returns static memory */ retlen = strlen (tcmd); @@ -6570,7 +6583,7 @@ xparse_dolparen (base, string, indp, flags) old value will be restored by restore_parser_state(). */ expand_aliases = 0; #if defined (EXTENDED_GLOB) - global_extglob = extended_glob; + global_extglob = extended_glob; /* for reset_parser() */ #endif token_to_read = DOLPAREN; /* let's trick the parser */ @@ -6908,7 +6921,7 @@ cond_term () { WORD_DESC *op; COND_COM *term, *tleft, *tright; - int tok, lineno; + int tok, lineno, local_extglob; char *etext; /* Read a token. It can be a left paren, a `!', a unary operator, or a @@ -7022,11 +7035,12 @@ cond_term () } /* rhs */ + local_extglob = extended_glob; if (parser_state & PST_EXTPAT) extended_glob = 1; tok = read_token (READ); if (parser_state & PST_EXTPAT) - extended_glob = global_extglob; + extended_glob = local_extglob; parser_state &= ~(PST_REGEXP|PST_EXTPAT); if (tok == WORD) |