diff options
| author | Mikael Magnusson <mikachu@gmail.com> | 2026-06-04 09:06:02 +0200 |
|---|---|---|
| committer | Mikael Magnusson <mikachu@gmail.com> | 2026-06-10 05:20:50 +0200 |
| commit | e5e9caa2ee2188444e06ea1e162eb23375ca7538 (patch) | |
| tree | ce0dbc6605b107f93277e56bf51940369372d2f1 | |
| parent | unposted: NEWS: document COLUMNS+LINES change from w/54676 (diff) | |
| download | zsh-e5e9caa2ee2188444e06ea1e162eb23375ca7538.tar zsh-e5e9caa2ee2188444e06ea1e162eb23375ca7538.tar.gz zsh-e5e9caa2ee2188444e06ea1e162eb23375ca7538.tar.bz2 zsh-e5e9caa2ee2188444e06ea1e162eb23375ca7538.tar.lz zsh-e5e9caa2ee2188444e06ea1e162eb23375ca7538.tar.xz zsh-e5e9caa2ee2188444e06ea1e162eb23375ca7538.tar.zst zsh-e5e9caa2ee2188444e06ea1e162eb23375ca7538.zip | |
54674: ::= didn't respect parameter flags
The documentation says
${name::=word}
In the first form, if name is unset then set it to word; in
the second form, if name is unset or null then set it to word;
and in the third form, unconditionally set name to word. In
all forms, the value of the parameter is then substituted.
Particularly that "the value of the parameter is substituted", not "the
word is substituted".
This is what happens before the fix, and similarly for array flags like "unique":
% typeset -E3 fl; hi=5; echo ${fl::=hi}
hi
% echo $fl
5.00e+00
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | Src/subst.c | 16 | ||||
| -rw-r--r-- | Test/D04parameter.ztst | 13 |
3 files changed, 31 insertions, 3 deletions
@@ -1,3 +1,8 @@ +2026-06-10 Mikael Magnusson <mikachu@gmail.com> + + * 54674: Src/subst.c, Test/D04parameter.ztst: ::= didn't respect + parameter flags + 2026-06-08 dana <dana@dana.is> * unposted: NEWS: document COLUMNS+LINES change from w/54676 diff --git a/Src/subst.c b/Src/subst.c index 16a3cb055..f72a6baf2 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3300,13 +3300,23 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, Param pm = sethparam(idbeg, a); if (pm) aval = paramvalarr(pm->gsu.h->getfn(pm), hkeys|hvals); - } else - setaparam(idbeg, a); + } else { + Param pm = setaparam(idbeg, a); + if (pm) + aval = pm->gsu.a->getfn(pm); + } isarr = 1; arrasg = 0; } else { untokenize(val); - setsparam(idbeg, ztrdup(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); + } } *idend = sav; copied = 1; diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 68c4ec288..57de28c72 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -82,6 +82,19 @@ >wasnull2d >wasnull2d + typeset -Z3 zerothree + print ${zerothree::=15} + 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} +0:::= respects expansion flags +>015 +>5.00e+00 +>1 2 3 + unset array print ${#${(A)=array=word}} 0:${#${(A)=array=word}} counts array elements |
