[PATCH] Do not export references even when ALLEXPORT is enabled
Philippe Altherr <[email protected]> Fri, 10 Jul 2026 14:39:08 +0200
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAGdYchshT+gNK4PUbnX97H2gVWZfjaBLk54BNRuN_jhMB2PayA@mail.gmail.com> |
References can't be flagged for export: % typeset -n -x ref=var typeset: -x not allowed with -n Nevertheless, references get exported when the option ALLEXPORT is enabled: % setopt ALLEXPORT % typeset -n ref=var % typeset -p ref export -n ref=var - Do not export references even when ALLEXPORT is enabled <https://github.com/paltherr/zsh/compare/fix-allexport-of-references-start...paltherr:zsh:fix-allexport-of-references> Philippe
fix-allexport-of-references.txt
(text/plain, 1.3 KB)
diff --git a/Src/params.c b/Src/params.c
index 8ea053035..7019ec8e0 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1167,7 +1167,7 @@ createparam(char *name, int flags)
paramtab->addnode(paramtab, ztrdup(name), pm);
}
- if (isset(ALLEXPORT) && !(flags & PM_HASHELEM))
+ if (isset(ALLEXPORT) && !(flags & (PM_NAMEREF | PM_HASHELEM)))
flags |= PM_EXPORTED;
} else {
pm = (Param) hcalloc(sizeof *pm);
@@ -2835,7 +2835,8 @@ assignstrvalue(Value v, char *val, int flags)
setscope(v->pm);
if (errflag ||
((!v->pm->env && !(v->pm->node.flags & PM_EXPORTED) &&
- !(isset(ALLEXPORT) && !(v->pm->node.flags & PM_HASHELEM))) ||
+ !(isset(ALLEXPORT) &&
+ !(v->pm->node.flags & (PM_NAMEREF | PM_HASHELEM)))) ||
(v->pm->node.flags & PM_ARRAY) || v->pm->ename))
return;
export_param(v->pm);
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index 7281be430..1ed21906f 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -2392,4 +2392,14 @@ F:converting from association/array to string should work here too
>${refX} : ddd - ddd - ddd
>${var} : aaa - -
+ typeset -n ref1
+ setopt allexport
+ ref1=var
+ typeset -n ref2
+ unsetopt allexport
+ typeset -p ref1 ref2
+0:references are not exported
+>typeset -n ref1=var
+>typeset -n ref2
+
%clean