1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-03 10:21:46 +02:00

49069: literal interpretation of subscripts for unset of array/hash elements

This commit is contained in:
Bart Schaefer 2021-06-13 16:30:06 -07:00
parent 667901b6ba
commit 5b4a1626c2
3 changed files with 19 additions and 4 deletions

View file

@ -1,3 +1,8 @@
2021-06-13 Bart Schaefer <schaefer@zsh.org>
* 49069: NEWS, Src/builtin.c: literal interpretation of subscripts
for unset of array/hash elements
2021-06-02 Oliver Kiddle <opk@zsh.org>
* Akinori MUSHA: 48942: Functions/Zle/edit-command-line:

12
NEWS
View file

@ -7,6 +7,18 @@ Note also the list of incompatibilities in the README file.
Changes since 5.8
-----------------
When unsetting a hash element, the string enclosed in square brackets is
interpreted literally after any normal command-line-argument expansions.
Thus
unset "hash[$key]"
first expands $key as usual for a double-quoted string, and then interprets
that result as the exact hash element to unset. This differs from previous
versions of the shell, which would also remove a leading backslash for an
unusual subset of characters in the expansion of $key. Note this also
means, for example, that
unset 'hash[ab]cd]'
unsets the element with key "ab]cd" rather than silently doing nothing.
The function command learnt a -T option to declare a function and enable
tracing for it simultaneously.

View file

@ -3724,14 +3724,12 @@ bin_unset(char *name, char **argv, Options ops, int func)
while ((s = *argv++)) {
char *ss = strchr(s, '['), *subscript = 0;
if (ss) {
char *sse;
char *sse = ss + strlen(ss)-1;
*ss = 0;
if ((sse = parse_subscript(ss+1, 1, ']'))) {
if (*sse == ']') {
*sse = 0;
subscript = dupstring(ss+1);
*sse = ']';
remnulargs(subscript);
untokenize(subscript);
}
}
if ((ss && !subscript) || !isident(s)) {