about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Src/subst.c27
-rw-r--r--Test/D04parameter.ztst10
3 files changed, 33 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 28305e91d..43b251742 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-05-21  Peter Stephenson  <pws@csr.com>
+
+	* 18565: Src/subst.c, Test/D04parameter.ztst: when ${(u)...}
+	reduced an array from more than one element to example one
+	stuff happened.
+
 2003-05-19  Peter Stephenson  <pws@csr.com>
 
 	* 18548: Src/Zle/zle_main.c: memory leak when vared'ing arrays
diff --git a/Src/subst.c b/Src/subst.c
index dc5044959..89ecbab7a 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1951,25 +1951,32 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 	int i;
 	LinkNode on = n;
 
-	if (!aval[0] && !plan9) {
+	if (unique) {
+	    if(!copied)
+		aval = arrdup(aval);
+
+	    i = arrlen(aval);
+	    if (i > 1)
+		zhuniqarray(aval);
+	}
+	if ((!aval[0] || !aval[1]) && !plan9) {
+	    int vallen;
 	    if (aptr > (char *) getdata(n) &&
 		aptr[-1] == Dnull && *fstr == Dnull)
 		*--aptr = '\0', fstr++;
-	    y = (char *) hcalloc((aptr - ostr) + strlen(fstr) + 1);
+	    vallen = aval[0] ? strlen(aval[0]) : 0;
+	    y = (char *) hcalloc((aptr - ostr) + vallen + strlen(fstr) + 1);
 	    strcpy(y, ostr);
 	    *str = y + (aptr - ostr);
+	    if (vallen)
+	    {
+		strcpy(*str, aval[0]);
+		*str += vallen;
+	    }
 	    strcpy(*str, fstr);
 	    setdata(n, y);
 	    return n;
 	}
-	if (unique) {
-	    if(!copied)
-		aval = arrdup(aval);
-
-	    i = arrlen(aval);
-	    if (i > 1)
-		zhuniqarray(aval);
-	}
 	if (sortit) {
 	    if (!copied)
 		aval = arrdup(aval);
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 3327caf9d..5700a0722 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -589,3 +589,13 @@
 0:Parameters associated with (#m) flag
 >MATCH 16 20 MATCH
 >5
+
+  print -l JAMES${(u)${=:-$(echo yes yes)}}JOYCE
+  print -l JAMES${(u)${=:-$(echo yes yes she said yes i will yes)}}JOYCE
+0:Bug with (u) flag reducing arrays to one element
+>JAMESyesJOYCE
+>JAMESyes
+>she
+>said
+>i
+>willJOYCE