issue reported by Kerin Millar <kfm@plushkava.net>
- cond_term: restore extended_glob to a local copy; safer than using
global_extglob, which we will reserve for error recovery
+
+ 8/30
+ ----
+parse.y
+ - parse_comsub: don't clear the pushed string list; we might need it to
+ consume additional input to satisfy this command substitution. When
+ we restore the parser state, don't restore the pushed string list in
+ case we used it. From
+ https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1018727
+ - parse_comsub: don't modify extended_glob if parser_state includes
+ PST_EXTPAT, in which case we've already set extended_glob and
+ global_extglob appropriately. Only matters in compatibility mode.
+
+ 8/31
+ ----
+subst.c
+ - parameter_brace_transform: make sure we return an error if *xform
+ is '\0'. Report from Ivan Kapranov <koltiradw@yandex.ru>
tests/comsub3.sub f
tests/comsub4.sub f
tests/comsub5.sub f
+tests/comsub6.sub f
tests/comsub-eof.tests f
tests/comsub-eof0.sub f
tests/comsub-eof1.sub f
int *lenp, flags;
{
int peekc, r;
- int start_lineno, local_extglob;
+ 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
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);
/* 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 */
if (expand_aliases)
expand_aliases = posixly_correct != 0;
#if defined (EXTENDED_GLOB)
- if (shell_compatibility_level <= 51)
+ /* 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;
}
#if defined (EXTENDED_GLOB)
- if (shell_compatibility_level <= 51)
+ if (shell_compatibility_level <= 51 && was_extpat == 0)
extended_glob = local_extglob;
#endif
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)? */
}
}
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);
return ((char *)NULL);
}
- if (valid_parameter_transform (xform) == 0)
+ if (xform[0] == 0 || valid_parameter_transform (xform) == 0)
{
this_command_name = oname;
if (vtype == VT_VARIABLE)
-BUILD_DIR=/usr/local/build/chet/bash/bash-current
+BUILD_DIR=/usr/local/build/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
ok 9
ok 8
ok 8
+Mon Aug 29 20:03:02 EDT 2022
+post foo
+Mon Aug 29 20:03:02 EDT 2022
+post foo1
+Mon Aug 29 20:03:02 EDT 2022
+Mon Aug 29 20:03:02 EDT 2022 after
+7
+Mon Aug 29 20:03:02 EDT 2022
+hey after x
+./comsub6.sub: line 40: syntax error near unexpected token `)'
+./comsub6.sub: line 40: `math1)'
${THIS_SH} ./comsub3.sub
${THIS_SH} ./comsub4.sub
${THIS_SH} ./comsub5.sub
+${THIS_SH} ./comsub6.sub
--- /dev/null
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+DATE='Mon Aug 29 20:03:02 EDT 2022'
+shopt -s expand_aliases
+
+alias foo='echo $(echo $DATE)'
+alias foo1='echo $(echo $DATE) '
+
+foo
+echo post foo
+
+foo1
+echo post foo1
+
+alias comsub0='echo $(echo $DATE'
+comsub0)
+comsub0 ) after
+
+alias math0='echo $(( 4+3 )'
+math0)
+
+alias x='VAR=$(echo hey)'
+x
+foo
+
+echo $VAR after x
+
+alias math1='echo $( date )'
+math1)
declare -i foo
A
declare -A foo
+./new-exp10.sub: line 118: ${V@}: bad substitution
abcxxxdef
abcådef
ḅć
echo ${foo@a}
declare -p foo
+
+V=42
+echo ${V@} # error
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-# test the other uses of the 'K' tranform operator and its sibling 'k'
+# test the other uses of the 'K' transform operator and its sibling 'k'
# the associative array tests are performed separately, since that was the
# original motivation for this feature
foo=string