Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Fix ${foo:^bar} where bar is an associative array



The getaparam function checks that the returned value is an array,
otherwise returns NULL, the getsparam function does no such check,
so we get a stringified version of our associative array.

Before this patch,
% typeset -A foo=([one]=1 [two]=2 [three]=3) bar=([four]=4 [five]=5 [six]=6)
% print -f '_%s_' ${foo:^bar}; echo
_1__5 4 6_
% print -f '_%s_' ${foo:^^bar}; echo
_1__5 4 6__2__5 4 6__3__5 4 6_

After,
% print -f '_%s_' ${foo:^bar}; echo
_1__5__2__4__3__6_
% print -f '_%s_' ${foo:^^bar}; echo
_1__5__2__4__3__6_

A similar fix might also be possible for the :|/:* code, but I'm a little
too tired to figure out what's going on there. There are no other uses
of getaparam in subst.c than those at least.

(I also noticed that there are only 2 prior uses of gethparam and none
of gethkparam).

---
 Src/subst.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Src/subst.c b/Src/subst.c
index f0d6c7a7b1..56a29bf0a4 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3473,7 +3473,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 	    val = dupstring("");
 	} else {
 	    char *sval;
-	    zip = getaparam(s);
+	    zip = gethparam(s);
+	    if (!zip) {
+		zip = getaparam(s);
+	    }
 	    if (!zip) {
 		sval = getsparam(s);
 		if (sval)
-- 
2.38.1





Messages sorted by: Reverse Date, Date, Thread, Author