mirror of
https://github.com/zsh-users/zsh
synced 2024-10-06 07:59:22 +00:00
25364: fix k flag in hash subscript
This commit is contained in:
parent
0c9830d23c
commit
dc72699b6c
|
@ -263,9 +263,10 @@ testing for values or keys that do not exist.
|
|||
item(tt(k))(
|
||||
If used in a subscript on an associative array, this flag causes the keys
|
||||
to be interpreted as patterns, and returns the value for the first key
|
||||
found where var(exp) is matched by the key. This flag does not work on
|
||||
the left side of an assignment to an associative array element. If used
|
||||
on another type of parameter, this behaves like `tt(r)'.
|
||||
found where var(exp) is matched by the key. Note this could be any
|
||||
such key as no ordering of associative arrays is defined.
|
||||
This flag does not work on the left side of an assignment to an associative
|
||||
array element. If used on another type of parameter, this behaves like `tt(r)'.
|
||||
)
|
||||
item(tt(K))(
|
||||
On an associative array this is like `tt(k)' but returns all values where
|
||||
|
|
|
@ -1127,7 +1127,11 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
|
|||
v->isarr &= ~SCANPM_WANTVALS;
|
||||
} else if (rev)
|
||||
v->isarr |= SCANPM_WANTVALS;
|
||||
if (!down && !keymatch && ishash)
|
||||
/*
|
||||
* This catches the case where we are using "k" (rather
|
||||
* than "K") on a hash.
|
||||
*/
|
||||
if (!down && keymatch && ishash)
|
||||
v->isarr &= ~SCANPM_MATCHMANY;
|
||||
}
|
||||
*inv = ind;
|
||||
|
|
|
@ -145,6 +145,16 @@
|
|||
>\2 backcbrack cbrack star
|
||||
>\\\4 \\\? star zounds
|
||||
|
||||
# It doesn't matter which element we get, since we never guarantee
|
||||
# ordering of an associative array. So just test the number of matches.
|
||||
array=(${(o)A[(k)\]]})
|
||||
print ${#array}
|
||||
array=(${(o)A[(k)\\\]]})
|
||||
print ${#array}
|
||||
0:Associative array keys interpreted as patterns, single match
|
||||
>1
|
||||
>1
|
||||
|
||||
typeset -g "A[one\"two\"three\"quotes]"=QQQ
|
||||
typeset -g 'A[one\"two\"three\"quotes]'=qqq
|
||||
print -R "$A[one\"two\"three\"quotes]"
|
||||
|
|
Loading…
Reference in a new issue