mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-22 13:27:58 +02:00
allow assignment to array keys @ and *; minor completion fix
This commit is contained in:
+12
-14
@@ -338,7 +338,13 @@ assign_array_element (name, value, flags)
|
||||
entry = find_variable (vname);
|
||||
isassoc = entry && assoc_p (entry);
|
||||
|
||||
if (((isassoc == 0 || (flags & ASS_NOEXPAND) == 0) && (ALL_ELEMENT_SUB (sub[0]) && sub[1] == ']')) || (sublen <= 1))
|
||||
/* We don't allow assignment to `*' or `@' associative array keys if the
|
||||
caller hasn't told us the subscript has already been expanded
|
||||
(ASS_NOEXPAND). If the caller has explicitly told us it's ok
|
||||
(ASS_ALLOWALLSUB) we allow it. */
|
||||
if (((isassoc == 0 || (flags & (ASS_NOEXPAND|ASS_ALLOWALLSUB)) == 0) &&
|
||||
(ALL_ELEMENT_SUB (sub[0]) && sub[1] == ']')) ||
|
||||
(sublen <= 1))
|
||||
{
|
||||
free (vname);
|
||||
err_badarraysub (name);
|
||||
@@ -564,12 +570,9 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
|
||||
{
|
||||
WORD_LIST *list;
|
||||
char *akey, *aval, *k, *v;
|
||||
int free_aval;
|
||||
|
||||
for (list = nlist; list; list = list->next)
|
||||
{
|
||||
free_aval = 0;
|
||||
|
||||
k = list->word->word;
|
||||
v = list->next ? list->next->word->word : 0;
|
||||
|
||||
@@ -577,24 +580,22 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
|
||||
list = list->next;
|
||||
|
||||
akey = expand_assignment_string_to_string (k, 0);
|
||||
aval = expand_assignment_string_to_string (v, 0);
|
||||
|
||||
if (akey == 0 || *akey == 0)
|
||||
{
|
||||
err_badarraysub (k);
|
||||
FREE (akey);
|
||||
continue;
|
||||
}
|
||||
|
||||
aval = expand_assignment_string_to_string (v, 0);
|
||||
if (aval == 0)
|
||||
{
|
||||
aval = (char *)xmalloc (1);
|
||||
aval[0] = '\0'; /* like do_assignment_internal */
|
||||
free_aval = 1;
|
||||
}
|
||||
|
||||
bind_assoc_var_internal (var, h, akey, aval, flags);
|
||||
if (free_aval)
|
||||
free (aval);
|
||||
free (aval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -714,13 +715,10 @@ assign_compound_array_list (var, nlist, flags)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ALL_ELEMENT_SUB (w[1]) && len == 2)
|
||||
if (ALL_ELEMENT_SUB (w[1]) && len == 2 && array_p (var))
|
||||
{
|
||||
set_exit_status (EXECUTION_FAILURE);
|
||||
if (assoc_p (var))
|
||||
report_error (_("%s: invalid associative array key"), w);
|
||||
else
|
||||
report_error (_("%s: cannot assign to non-numeric index"), w);
|
||||
report_error (_("%s: cannot assign to non-numeric index"), w);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user