1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-01 04:46:08 +02:00

19707: negative index into arrays should return scalar and not one element array

This commit is contained in:
Oliver Kiddle 2004-03-30 16:35:30 +00:00
parent 43513b4288
commit 3023ddf132
3 changed files with 24 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2004-03-30 Oliver Kiddle <opk@zsh.org>
* 19707: Src/params.c, Test/D05array.ztst: fix bug where a
nagative index into an array returned a one element array
instead of a scalar
2004-03-25 Clint Adams <clint@zsh.org>
* 19691: Completion/Unix/Type/_diff_options: Allow more than
@ -65,7 +71,7 @@
the parameter was previously exported.
* 19655: Src/params.c: the reverse pointer from a tied array
to a tied scalar wasn't delete if the array was unset by unsetting
to a tied scalar wasn't deleted if the array was unset by unsetting
the scalar (or probably vice versa).
2004-03-17 Peter Stephenson <pws@csr.com>

View File

@ -1272,13 +1272,14 @@ getindex(char **pptr, Value v, int dq)
} else {
end = we ? we : start;
}
if (start != end) com = 1;
if (start > 0)
start--;
else if (start == 0 && end == 0)
end++;
if (s == tbrack) {
s++;
if (v->isarr && start == end-1 && !com &&
if (v->isarr && !com &&
(!(v->isarr & SCANPM_MATCHMANY) ||
!(v->isarr & (SCANPM_MATCHKEY | SCANPM_MATCHVAL |
SCANPM_KEYMATCH))))

View File

@ -3,6 +3,7 @@
%prep
foo=(a b c d e f g)
arr=(foo bar baz)
mkdir array.tmp
touch array.tmp/{1..9}
@ -60,6 +61,20 @@
0:A slice with a negative start and end
>.b c d e f.
echo .${${arr[2]}[1]}.
echo .${${arr[-2]}[1]}.
echo .${${arr[2,2]}[1]}.
echo .${${arr[-2,-2]}[1]}.
echo .${${arr[2,-2]}[1]}.
echo .${${arr[-2,2]}[1]}.
0:Slices should return an array, elements a scalar
>.b.
>.b.
>.bar.
>.bar.
>.bar.
>.bar.
setopt ksh_arrays
echo .${foo[1,2]}.
unsetopt ksh_arrays