diff --git a/NEWS b/NEWS index 5b191a86f..04d9b2dc5 100644 --- a/NEWS +++ b/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 diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index f85a72eb2..5c14866eb 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -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); diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 95a1a5593..4cc62d08e 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -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. */ diff --git a/src/cmd/ksh93/tests/types.sh b/src/cmd/ksh93/tests/types.sh index eea70e0c2..a64903000 100755 --- a/src/cmd/ksh93/tests/types.sh +++ b/src/cmd/ksh93/tests/types.sh @@ -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))