mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 03:32:24 +00:00
Fix spurious export attribute when printing compound variables
Reproducer script: typeset -Ttyp1 typ1=( function get { .sh.value="'Sample'"; } ) typ1 var11 typeset -p .sh.type typeset -p .sh.type Buggy output: namespace sh.type { typeset -r typ1='Sample' } namespace sh.type { typeset -x -r typ1='Sample' } An -x (export) attribute is magically pulled out of a hat. Analysis: The walk_tree() function in nvdisc.c repurposes (!) the NV_EXPORT attribute as an instruction to turn *off* indenting when pretty-printing the values of compound variables. The print_namval() function in typeset.c, implementing 'typeset -p', turns on NV_EXPORT for compound variables to inhibit indentation. But it then does not bother to turn it off, which causes this bug. src/cmd/ksh93/bltins/typeset.c: print_namval(): - When printing compound variables, only turn on NV_EXPORT temporarily. Resolves: https://github.com/ksh93/ksh/issues/456
This commit is contained in:
parent
80f8cc497f
commit
9da0887e54
4 changed files with 56 additions and 3 deletions
5
NEWS
5
NEWS
|
@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2022-06-07:
|
||||
|
||||
- Fixed a bug in 'typeset' where compound variables could acquire a spurious
|
||||
-x (export) attribute when printing their values, triggering other bugs.
|
||||
|
||||
2022-06-05:
|
||||
|
||||
- Fixed a bug where tab completion would spuriously execute a command
|
||||
|
|
|
@ -1432,6 +1432,7 @@ static int print_namval(Sfio_t *file,register Namval_t *np,register int flag, st
|
|||
{
|
||||
register char *cp;
|
||||
int indent=tp->indent, outname=0, isfun;
|
||||
char tempexport=0;
|
||||
sh_sigcheck();
|
||||
if(flag)
|
||||
flag = '\n';
|
||||
|
@ -1523,9 +1524,19 @@ static int print_namval(Sfio_t *file,register Namval_t *np,register int flag, st
|
|||
print_value(file,np,tp);
|
||||
return(0);
|
||||
}
|
||||
if(nv_isvtree(np))
|
||||
if(nv_isvtree(np) && !nv_isattr(np,NV_EXPORT))
|
||||
{
|
||||
/*
|
||||
* Compound variable. Repurpose NV_EXPORT to tell walk_tree() in nvdisc.c not
|
||||
* to indent the nv_getval() output. Also turn it back off, or bugs will happen.
|
||||
*/
|
||||
nv_onattr(np,NV_EXPORT);
|
||||
if(cp=nv_getval(np))
|
||||
tempexport++;
|
||||
}
|
||||
cp = nv_getval(np);
|
||||
if(tempexport)
|
||||
nv_offattr(np,NV_EXPORT);
|
||||
if(cp)
|
||||
{
|
||||
if(indent)
|
||||
sfnputc(file,'\t',indent);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
||||
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
|
||||
#define SH_RELEASE_DATE "2022-06-05" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_DATE "2022-06-07" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
|
||||
|
||||
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
||||
|
|
|
@ -734,5 +734,42 @@ exp=8
|
|||
[[ $got == $exp ]] || err_exit "short integer arrays in types isn't working correctly" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# Printing .sh.type should not crash or give variables a spurious -x attribute.
|
||||
# https://github.com/ksh93/ksh/issues/456
|
||||
|
||||
got=$("$SHELL" -c 'typeset -p .sh.type
|
||||
typeset -Ttyp1 typ1=(
|
||||
function get {
|
||||
.sh.value="'\''Sample'\''";
|
||||
}
|
||||
)
|
||||
typeset -p .sh.type
|
||||
typ1
|
||||
command typ1 var11
|
||||
typ1
|
||||
print $var11
|
||||
print -v var11
|
||||
typeset -p .sh.type' 2>&1)
|
||||
|
||||
exp='namespace sh.type
|
||||
{
|
||||
:
|
||||
}
|
||||
namespace sh.type
|
||||
{
|
||||
typeset -r typ1='\''Sample'\''
|
||||
}
|
||||
typ1 var11='\''Sample'\''
|
||||
'\''Sample'\''
|
||||
'\''Sample'\''
|
||||
namespace sh.type
|
||||
{
|
||||
typeset -r typ1='\''Sample'\''
|
||||
}'
|
||||
|
||||
[[ $got == "$exp" ]] || err_exit "'tyeset -p .sh.type' failed" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Reference in a new issue