mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
typeset -p: fix output of nonexistent [0]= array element (#451)
This fix was backported from ksh 93v- 2012-10-04. src/cmd/ksh93/sh/nvtree.c: nv_outnode(): - If the array is supposed to be empty, do not continue. This avoids outputting a nonexistent [0]= element for empty arrays. Resolves: https://github.com/ksh93/ksh/issues/420 Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
fb696ecfae
commit
a8dd1bbd9d
4 changed files with 38 additions and 2 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.
|
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
|
|
||||||
|
2022-02-04:
|
||||||
|
|
||||||
|
- Fixed a bug in 'typeset -p': for an indexed array variable that is set
|
||||||
|
but empty, it will no longer output a nonexistent '[0]=' element.
|
||||||
|
|
||||||
2022-02-02:
|
2022-02-02:
|
||||||
|
|
||||||
- Fixed the -a/allexport option to export all variables that are assigned
|
- Fixed the -a/allexport option to export all variables that are assigned
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
#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_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
|
||||||
#define SH_RELEASE_DATE "2022-02-02" /* must be in this format for $((.sh.version)) */
|
#define SH_RELEASE_DATE "2022-02-04" /* must be in this format for $((.sh.version)) */
|
||||||
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
|
#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. */
|
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
||||||
|
|
|
@ -556,9 +556,11 @@ void nv_outnode(Namval_t *np, Sfio_t* out, int indent, int special)
|
||||||
Indent = indent;
|
Indent = indent;
|
||||||
if(ap)
|
if(ap)
|
||||||
{
|
{
|
||||||
|
sfputc(out,'(');
|
||||||
|
if(array_elem(ap)==0)
|
||||||
|
return;
|
||||||
if(!(ap->nelem&ARRAY_SCAN))
|
if(!(ap->nelem&ARRAY_SCAN))
|
||||||
nv_putsub(np,NIL(char*),ARRAY_SCAN);
|
nv_putsub(np,NIL(char*),ARRAY_SCAN);
|
||||||
sfputc(out,'(');
|
|
||||||
if(indent>=0)
|
if(indent>=0)
|
||||||
{
|
{
|
||||||
sfputc(out,'\n');
|
sfputc(out,'\n');
|
||||||
|
|
|
@ -754,5 +754,34 @@ got=$("$SHELL" -c 'test -z ${foo[${bar}..${baz}]}' 2>&1)
|
||||||
[[ -z $got ]] || err_exit $'Using ${foo[${bar}..${baz}]} when the variable ${foo} isn\'t set fails in error' \
|
[[ -z $got ]] || err_exit $'Using ${foo[${bar}..${baz}]} when the variable ${foo} isn\'t set fails in error' \
|
||||||
"(got $(printf %q "$got"))"
|
"(got $(printf %q "$got"))"
|
||||||
|
|
||||||
|
# ======
|
||||||
|
# Spurious '[0]=' element in 'typeset -p' output for indexed array variable that is set but empty
|
||||||
|
# https://github.com/ksh93/ksh/issues/420
|
||||||
|
# https://github.com/att/ast/issues/69#issuecomment-325435618
|
||||||
|
exp='len=0: typeset -a Y_ARR=()'
|
||||||
|
got=$("$SHELL" -c '
|
||||||
|
typeset -a Y_ARR
|
||||||
|
function Y_ARR.unset {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
print -n "len=${#Y_ARR[@]}: "
|
||||||
|
typeset -p Y_ARR
|
||||||
|
')
|
||||||
|
[[ $exp == $got ]] || err_exit 'Giving an array a .unset discipline function adds a spurious [0] element' \
|
||||||
|
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||||
|
|
||||||
|
# https://github.com/att/ast/issues/69#issuecomment-325551035
|
||||||
|
exp='len=0: typeset -a X_ARR=()'
|
||||||
|
got=$("$SHELL" -c '
|
||||||
|
typeset -a X_ARR=(aa bb cc)
|
||||||
|
unset X_ARR[2]
|
||||||
|
unset X_ARR[1]
|
||||||
|
unset X_ARR[0]
|
||||||
|
print -n "len=${#X_ARR[@]}: "
|
||||||
|
typeset -p X_ARR
|
||||||
|
')
|
||||||
|
[[ $exp == $got ]] || err_exit 'Unsetting all elements of an array adds a spurious [0] element' \
|
||||||
|
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue