1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +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:
Martijn Dekker 2022-06-07 04:16:48 +01:00
parent 80f8cc497f
commit 9da0887e54
4 changed files with 56 additions and 3 deletions

View file

@ -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))