zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Fix ${foo:^bar} where bar is an associative array
@ 2024-04-05 22:35 Mikael Magnusson
  0 siblings, 0 replies; only message in thread
From: Mikael Magnusson @ 2024-04-05 22:35 UTC (permalink / raw)
  To: zsh-workers

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-05 22:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 22:35 PATCH: Fix ${foo:^bar} where bar is an associative array Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).