1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-09-21 19:31:50 +02:00

25364: fix k flag in hash subscript

This commit is contained in:
Peter Stephenson 2008-07-31 13:53:28 +00:00
parent 0c9830d23c
commit dc72699b6c
3 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -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]"