print_cmd.c
- print_function_def,named_function_string: pass POSIXLY_CORRECT to
valid_function_name as the FLAGS argument
+
+ 2/6
+ ---
+subst.c
+ - expand_subscript_string: don't set W_NOTILDE in td.flags so we
+ perform `normal' tilde expansion (expansion at the start of the
+ word) on the array subscript
+ - expand_oneword,expand_compound_assignment_word: change second arg to
+ ATYPE, which better reflects its use
+
+arrayfunc.c
+ - assign_assoc_from_kvlist,assign_compound_array_list,expand_and_quote_assoc_word:
+ use expand_assignment_string_to_string instead of expand_subscript_string
+ for the rhs of the assignment or the second word in the kvpair to
+ be more consistent with how assignment statements behave (e.g.,
+ tilde expansion). Fixes issue reported by maroloccio@gmail.com
tests/array28.sub f
tests/array29.sub f
tests/array30.sub f
+tests/array31.sub f
tests/array-at-star f
tests/array2.right f
tests/assoc.tests f
tests/assoc16.sub f
tests/assoc17.sub f
tests/assoc18.sub f
-tests/attr.tests f
+tests/assoc19.sub f
+`tests/attr.tests f
tests/attr.right f
tests/attr1.sub f
tests/attr2.sub f
continue;
}
- aval = expand_subscript_string (v, 0);
+ aval = expand_assignment_string_to_string (v, 0);
if (aval == 0)
{
aval = (char *)xmalloc (1);
/* See above; we need to expand the value here */
if (assoc_p (var))
{
- val = expand_subscript_string (val, 0);
+ val = expand_assignment_string_to_string (val, 0);
if (val == 0)
{
val = (char *)xmalloc (1);
nword[i++] = w[ind++];
nword[i++] = w[ind++];
- t = expand_subscript_string (w+ind, 0);
+
+ t = expand_assignment_string_to_string (w+ind, 0);
s = (t && strchr (t, CTLESC)) ? quote_escapes (t) : t;
value = sh_single_quote (s ? s : "");
if (s != t)
oe = expand_no_split_dollar_star;
ret = (char *)NULL;
+#if 0
td.flags = W_NOPROCSUB|W_NOTILDE|W_NOSPLIT2; /* XXX - W_NOCOMSUB? */
+#else
+ td.flags = W_NOPROCSUB|W_NOSPLIT2; /* XXX - W_NOCOMSUB? */
+#endif
td.word = savestring (string); /* in case it's freed on error */
expand_no_split_dollar_star = 1;
exp = substring (string, si+1, ni);
t = expand_subscript_string (exp, quoted & ~(Q_ARITH|Q_DOUBLE_QUOTES));
free (exp);
+ /* XXX - use sh_single_quote here? */
exp = t ? sh_backslash_quote (t, abstab, 0) : savestring ("");
free (t);
['expanded-ind']='expanded-value'. */
static WORD_LIST *
-expand_oneword (char *value, int flags)
+expand_oneword (char *value, int atype)
{
WORD_LIST *l, *nl;
char *t;
int kvpair;
- if (flags == 0)
+ if (atype == 0)
{
/* Indexed array */
- l = expand_compound_array_assignment ((SHELL_VAR *)NULL, value, flags);
+ l = expand_compound_array_assignment ((SHELL_VAR *)NULL, value, atype);
/* Now we quote the results of the expansion above to prevent double
expansion. */
- quote_compound_array_list (l, flags);
+ quote_compound_array_list (l, atype);
return l;
}
else
if ((nl->word->flags & W_ASSIGNMENT) == 0)
t = sh_single_quote (nl->word->word ? nl->word->word : "");
else
- t = expand_and_quote_assoc_word (nl->word->word, flags);
+ t = expand_and_quote_assoc_word (nl->word->word, atype);
free (nl->word->word);
nl->word->word = t;
}
handling, see expand_oneword() above. The return value is
NAME[+]=( expanded-and-quoted-VALUE ). */
static void
-expand_compound_assignment_word (WORD_LIST *tlist, int flags)
+expand_compound_assignment_word (WORD_LIST *tlist, int atype)
{
WORD_LIST *l;
int wlen, oind, t;
value = extract_array_assignment_list (tlist->word->word + t + 1, &oind);
/* This performs one round of expansion on the index/key and value and
single-quotes each word in the result. */
- l = expand_oneword (value, flags);
+ l = expand_oneword (value, atype);
free (value);
value = string_list (l);
declare -Au A=([Darwin]="FOO" )
FOO
declare -Au A=(["@"]="FOO" )
+declare -a aa=([0]="/homes/cj/Desktop")
+declare -a aa=([0]="/homes/cj/Desktop")
+declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
+declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
+declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
+declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
${THIS_SH} ./array28.sub
${THIS_SH} ./array29.sub
${THIS_SH} ./array30.sub
+${THIS_SH} ./array31.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/>.
+#
+
+# Tilde expansion in indexed array assignments; prep for future work
+HOME=/homes/cj
+
+declare -a aa
+aa=([0]=~/Desktop)
+declare -p aa
+unset aa
+
+declare -a aa=([0]=~/Desktop)
+declare -p aa
+unset aa
+
+declare -a aa=([0]=~/Desktop:~/Library:~/Documents)
+declare -p aa
+unset aa
+
+declare -a aa
+aa=([0]=~/Desktop:~/Library:~/Documents)
+declare -p aa
+unset aa
+
+declare -a aa=([0]=~/Desktop:~/Library:~/Documents [1]=~/Applications)
+declare -p aa
+unset aa
+
+declare -a aa
+aa=([0]=~/Desktop:~/Library:~/Documents [1]=~/Applications)
+declare -p aa
+unset aa
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
5: ok 1
+declare -A aa=([key]="/homes/cj/Desktop" )
+declare -A aa=([key]="/homes/cj/Desktop" )
+declare -A aa=([k2]="/homes/cj/Library" [key]="/homes/cj/Desktop" )
+declare -A aa=([/homes/cj/key]="/homes/cj/Desktop" )
+declare -A aa=([/homes/cj/Documents]="/homes/cj/Library" [/homes/cj/key]="/homes/cj/Desktop" )
+declare -A aa=([/homes/cj/Documents]="/homes/cj/Library" [/homes/cj/key]="/homes/cj/Desktop:/homes/cj/Documents:/homes/cj/Applications" )
+declare -A aa=([/homes/cj/Documents]="/homes/cj/Library" [/homes/cj/key]="/homes/cj/Desktop:/homes/cj/Documents:/homes/cj/Applications" )
# tests with `[' and `]' subscripts and printf/read/wait builtins
${THIS_SH} ./assoc18.sub
+# tests with tilde expansion in keys and values post-bash-5.2
+${THIS_SH} ./assoc19.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/>.
+#
+# Problems with tilde expansion of keys and values in bash-5.2
+
+HOME=/homes/cj
+
+declare -A aa=([key]=~/Desktop)
+declare -p aa
+unset aa
+
+declare -A aa
+aa=([key]=~/Desktop)
+declare -p aa
+unset aa
+
+declare -A aa=([key]=~/Desktop [k2]=~/Library )
+declare -p aa
+unset aa
+
+declare -A aa=([~/key]=~/Desktop)
+declare -p aa
+unset aa
+
+declare -A aa
+aa=([~/key]=~/Desktop)
+aa[~/Documents]=~/Library
+declare -p aa
+unset aa
+
+declare -A aa
+aa=([~/key]=~/Desktop:~/Documents:~/Applications)
+aa[~/Documents]=~/Library
+declare -p aa
+unset aa
+
+declare -A aa=([~/key]=~/Desktop:~/Documents:~/Applications [~/Documents]=~/Library)
+declare -p aa
+
+