parse extended glob patterns in command substitutions in compatibility mode, even if extglob is not set

This commit is contained in:
Chet Ramey
2022-08-02 11:16:48 -04:00
parent e9e3e4fea5
commit 9c317a6ae1
74 changed files with 22157 additions and 19321 deletions
+42 -7
View File
@@ -1666,7 +1666,7 @@ rewind_input_string ()
xchars++;
/* XXX - how to reflect bash_input.location.string back to string passed to
parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
far into the string we parsed. parse_and_execute knows where bash_input.
location.string is, and how far from orig_string that is -- that's the
number of characters the command consumed. */
@@ -3303,7 +3303,7 @@ reset_parser ()
#if defined (EXTENDED_GLOB)
/* Reset to global value of extended glob */
if (parser_state & PST_EXTPAT)
if (parser_state & (PST_EXTPAT|PST_CMDSUBST))
extended_glob = global_extglob;
#endif
@@ -3328,6 +3328,11 @@ reset_parser ()
eol_ungetc_lookahead = 0;
/* added post-bash-5.1 */
need_here_doc = 0;
redir_stack[0] = 0;
esacs_needed_count = expecting_in_token = 0;
current_token = '\n'; /* XXX */
last_read_token = '\n';
token_to_read = '\n';
@@ -4098,6 +4103,7 @@ parse_comsub (qc, open, close, lenp, flags)
saved_global = global_command; /* might not be necessary */
global_command = (COMMAND *)NULL;
/* These are reset by reset_parser() */
need_here_doc = 0;
esacs_needed_count = expecting_in_token = 0;
@@ -4107,9 +4113,13 @@ parse_comsub (qc, open, close, lenp, flags)
backwards compatibility. */
if (expand_aliases)
expand_aliases = posixly_correct != 0;
#if defined (EXTENDED_GLOB)
global_extglob = extended_glob;
if (shell_compatibility_level <= 51)
extended_glob = 1;
#endif
current_token = '\n'; /* XXX */
token_to_read = DOLPAREN; /* let's trick the parser */
r = yyparse ();
@@ -4120,11 +4130,20 @@ parse_comsub (qc, open, close, lenp, flags)
gather_here_documents (); /* XXX check compatibility level? */
}
#if defined (EXTENDED_GLOB)
extended_glob = global_extglob;
#endif
parsed_command = global_command;
if (EOF_Reached)
/* yyparse() has already called yyerror() */
return (&matched_pair_error);
{
shell_eof_token = ps.eof_token;
expand_aliases = ps.expand_aliases;
/* yyparse() has already called yyerror() and reset_parser() */
return (&matched_pair_error);
}
else if (r != 0)
{
/* parser_error (start_lineno, _("could not parse command substitution")); */
@@ -4135,13 +4154,26 @@ parse_comsub (qc, open, close, lenp, flags)
if (interactive_shell == 0)
jump_to_top_level (FORCE_EOF); /* This is like reader_loop() */
else
jump_to_top_level (DISCARD);
{
shell_eof_token = ps.eof_token;
expand_aliases = ps.expand_aliases;
jump_to_top_level (DISCARD);
}
}
if (current_token != shell_eof_token)
{
INTERNAL_DEBUG(("current_token (%d) != shell_eof_token (%c)", current_token, shell_eof_token));
token_to_read = current_token;
/* If we get here we can check eof_encountered and if it's 1 but the
previous EOF_Reached test didn't succeed, we can assume that the shell
is interactive and ignoreeof is set. We might want to restore the
parser state in this case. */
shell_eof_token = ps.eof_token;
expand_aliases = ps.expand_aliases;
return (&matched_pair_error);
}
@@ -4226,6 +4258,9 @@ xparse_dolparen (base, string, indp, flags)
command substitution and we want to defer it completely until then. The
old value will be restored by restore_parser_state(). */
expand_aliases = 0;
#if defined (EXTENDED_GLOB)
global_extglob = extended_glob;
#endif
token_to_read = DOLPAREN; /* let's trick the parser */
@@ -4236,7 +4271,7 @@ xparse_dolparen (base, string, indp, flags)
if (current_token == shell_eof_token)
yyclearin; /* might want to clear lookahead token unconditionally */
reset_parser ();
reset_parser (); /* resets extended_glob too */
/* reset_parser() clears shell_input_line and associated variables, including
parser_state, so we want to reset things, then restore what we need. */
restore_input_line_state (&ls);