about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--Src/params.c3
-rw-r--r--Test/D05array.ztst15
3 files changed, 24 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 5da29cf7a..0a234a790 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
diff --git a/Src/params.c b/Src/params.c
index 49c3a93d7..134355173 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -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))))
diff --git a/Test/D05array.ztst b/Test/D05array.ztst
index 35976899c..5ca83ee6d 100644
--- a/Test/D05array.ztst
+++ b/Test/D05array.ztst
@@ -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