From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Fix ${foo:^bar} where bar is an associative array
Date: Sat, 6 Apr 2024 00:35:23 +0200 [thread overview]
Message-ID: <20240405223523.29765-1-mikachu@gmail.com> (raw)
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
reply other threads:[~2024-04-05 22:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240405223523.29765-1-mikachu@gmail.com \
--to=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).