summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2026-06-19 21:33:34 +0200
committerMikael Magnusson <mikachu@gmail.com>2026-06-21 09:26:14 +0200
commitc4e0b3cfd15a82261295dad8c242b874079ae79c (patch)
treed9b0f8a28ac99880133259a7edc1721d85f2b600
parent54790 (tweaked): _ffmpeg: update for modern ffmpeg (diff)
downloadzsh-c4e0b3cfd15a82261295dad8c242b874079ae79c.tar
zsh-c4e0b3cfd15a82261295dad8c242b874079ae79c.tar.gz
zsh-c4e0b3cfd15a82261295dad8c242b874079ae79c.tar.bz2
zsh-c4e0b3cfd15a82261295dad8c242b874079ae79c.tar.lz
zsh-c4e0b3cfd15a82261295dad8c242b874079ae79c.tar.xz
zsh-c4e0b3cfd15a82261295dad8c242b874079ae79c.tar.zst
zsh-c4e0b3cfd15a82261295dad8c242b874079ae79c.zip
54822: the ::= fix in 54674 was incomplete
% foo=xxx; () { echo ${2::=$foo} } yyy yyy We get the argv parameter returned when asking for "2" so use getvalue() to get a vbuf with the proper start/end set instead of making up bogus values.
-rw-r--r--ChangeLog5
-rw-r--r--Src/subst.c26
-rw-r--r--Test/D04parameter.ztst39
3 files changed, 63 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index defed2e38..0f3135b93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2026-06-21 Mikael Magnusson <mikachu@gmail.com>
+
+ * 54822: Src/subst.c, Test/D04parameter.ztst: the ::= fix in
+ 54674 was incomplete
+
2026-06-20 dana <dana@dana.is>
* Nuke: 54790 (tweaked): Completion/Unix/Command/_ffmpeg:
diff --git a/Src/subst.c b/Src/subst.c
index f432d3029..eef713a8c 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3304,8 +3304,14 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
aval = paramvalarr(pm->gsu.h->getfn(pm), hkeys|hvals);
} else {
Param pm = setaparam(idbeg, a);
- if (pm)
- aval = pm->gsu.a->getfn(pm);
+ if (pm) {
+ struct value vbuf = { 0 };
+ char *p = idbeg;
+ Value v = getvalue(&vbuf, &p, 1);
+ if (v) {
+ aval = getarrvalue(v);
+ }
+ }
}
isarr = 1;
arrasg = 0;
@@ -3313,11 +3319,17 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
untokenize(val);
Param pm = setsparam(idbeg, ztrdup(val));
if (pm) {
- struct value vbuf = { 0 };
- vbuf.pm = pm;
- vbuf.end = -1;
- vbuf.valflags = VALFLAG_SUBST;
- val = getstrvalue(&vbuf);
+ /* this check isn't needed for correctness, but array values
+ * aren't affected by SUBST flags anyway */
+ if ((PM_TYPE(pm->node.flags) & (PM_HASHED|PM_ARRAY)) == 0) {
+ struct value vbuf = { 0 };
+ char *p = idbeg;
+ Value v = getvalue(&vbuf, &p, 1);
+ if (v) {
+ v->valflags = VALFLAG_SUBST;
+ val = ztrdup(getstrvalue(v));
+ }
+ }
}
}
*idend = sav;
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 97577fd4e..d6e0044ef 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -84,16 +84,55 @@
typeset -Z3 zerothree
print ${zerothree::=15}
+ zerothree=
+ print ${zerothree[1]::=2} $zerothree[1] $zerothree
+ zerothree=
+ print ${zerothree[1,2]::=34} $zerothree[1,2] $zerothree
+ zerothree=
+ print ${zerothree[2,3]::=7} $zerothree[2,3] $zerothree
typeset -E3 ethree
five=5
print ${ethree::=five}
typeset -a -U uniquearr
typeset -a duplicates=(1 2 1 1 2 3)
print ${(A)uniquearr::=$duplicates}
+ print ${(A)uniquearr[1,2]::=$duplicates}
+ typeset -a normalarray=( a b c d e )
+ print ${(A)normalarray[2,4]::=o}
+ typeset -u upper=aaaaa
+ print ${upper[2,3]::=hi} $upper $upper[2,3]
+ print ${(A)upper::=big} $upper ${(t)upper}
0:::= respects expansion flags
>015
+>0 0 002
+>03 03 034
+>07 07 007
>5.00e+00
>1 2 3
+>1 2
+>o e
+>HI AHIAA HI
+>big big array-local
+
+ local foo=xxx
+ () { echo ${2::=$foo} ${3::=$foo} ${4::=$foo}; echo $2 } yyy
+ () { echo ${11::=$foo}; echo $11 } yyy blah
+0:::= doesn't do weird things with positional arguments
+>xxx xxx xxx
+>xxx
+>xxx
+>xxx
+
+ local five=5 arr=( a b )
+ print -rl - ${arr[2]::=$five}
+ () { print -rl - ${1::=$2} } x y
+ () { print -rl - ${1::=$five} ${2::=$five} ${9::=$five} } x y
+0:regression: ::= with multiple assignments
+>5
+>y
+>5
+>5
+>5
unset array
print ${#${(A)=array=word}}