mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix the output of typeset -p for two dimensional indexed arrays (#454)
In ksh93v- 2012-10-04 the following bugfix is noted in the changelog
(this fix was most likely part of ksh93v- 2012-09-27, although that
version is not archived anywhere):
12-09-21 A bug in which the output of a two dimensional sparse
indexed array would cause the second subscript be treated
as an associative array when read back in has been fixed.
Elements that are sparse indexed arrays now are prefixed
type "typeset -a".
Below is a before and after of this change:
# Before
$ typeset -a foo[1][2]=bar
$ typeset -p foo
typeset -a foo=([1]=([2]=bar) )
# After
$ typeset -a foo[1][2]=bar
$ typeset -p foo
typeset -a foo=(typeset -a [1]=([2]=bar) )
src/cmd/ksh93/sh/*.c:
- Backport changes from ksh93v- to print 'typeset -a' before sparse
indexed arrays and properly handle 'typeset -a' in reinput
commands from 'typeset -p'.
src/cmd/ksh93/tests:
- Add two regression tests to arrays.sh for this change.
- Update the existing regression tests for compatibility with the
new printed typeset output.
This commit is contained in:
parent
e6d0187dd8
commit
787058bdbf
13 changed files with 80 additions and 16 deletions
|
|
@ -803,5 +803,21 @@ got=$(set +x; redirect 2>&1; foo[42]=''; : ${foo[42]:?})
|
|||
[[ $got == *"$exp" ]] || err_exit '${array[index]:?error} does not throw error' \
|
||||
"(expected match of *$(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# A multidimensional indexed array should be printed correctly by
|
||||
# 'typeset -p'. Additionally, the printed command must produce the
|
||||
# same result when reinput to the shell.
|
||||
unset foo
|
||||
typeset -a foo[1][2]=bar
|
||||
exp='typeset -a foo=(typeset -a [1]=([2]=bar) )'
|
||||
got=$(typeset -p foo)
|
||||
[[ $exp == "$got" ]] || err_exit "Multidimensional indexed arrays are not printed correctly with 'typeset -p'" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
unset foo
|
||||
typeset -a foo=(typeset -a [1]=([2]=bar) )
|
||||
got=$(typeset -p foo)
|
||||
[[ $exp == "$got" ]] || err_exit "Output from 'typeset -p' for indexed array cannot be used for reinput" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ done
|
|||
|
||||
$SHELL 2> /dev/null -c 'compound c;float -a c.ar;(( c.ar[2][3][3] = 5))' || 'multidimensional arrays in arithmetic expressions not working'
|
||||
|
||||
expected='typeset -a -l -E c.ar=([2]=([3]=([3]=5) ) )'
|
||||
expected='typeset -a -l -E c.ar=(typeset -a [2]=(typeset -a [3]=([3]=5) ) )'
|
||||
unset c
|
||||
float c.ar
|
||||
c.ar[2][3][3]=5
|
||||
|
|
|
|||
|
|
@ -668,7 +668,7 @@ compound -a c.board
|
|||
for ((i=2; i < 4; i++))
|
||||
do c.board[1][$i]=(foo=bar)
|
||||
done
|
||||
exp=$'(\n\ttypeset -C -a board=(\n\t\t[1]=(\n\t\t\t[2]=(\n\t\t\t\tfoo=bar\n\t\t\t)\n\t\t\t[3]=(\n\t\t\t\tfoo=bar\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
exp=$'(\n\ttypeset -C -a board=(\n\t\ttypeset -a [1]=(\n\t\t\t[2]=(\n\t\t\t\tfoo=bar\n\t\t\t)\n\t\t\t[3]=(\n\t\t\t\tfoo=bar\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
[[ "$(print -v c)" == "$exp" ]] || err_exit 'compound variable assignment to two dimensional array not working'
|
||||
|
||||
unset zz
|
||||
|
|
|
|||
|
|
@ -593,7 +593,7 @@ function read_c
|
|||
read -C v
|
||||
}
|
||||
print "( typeset -i x=36 ) " | read_c ar[5][9][2]
|
||||
exp=$'(\n\t[5]=(\n\t\t[9]=(\n\t\t\t[2]=(\n\t\t\t\ttypeset -i x=36\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
exp=$'(\n\ttypeset -a [5]=(\n\t\ttypeset -a [9]=(\n\t\t\t[2]=(\n\t\t\t\ttypeset -i x=36\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
[[ $(print -v ar) == "$exp" ]] || err_exit 'read into nameref of global array instance from within a function fails'
|
||||
|
||||
function read_c
|
||||
|
|
@ -606,7 +606,7 @@ function main
|
|||
compound -a ar
|
||||
nameref nar=ar
|
||||
print "( typeset -i x=36 ) " | read_c nar[5][9][2]
|
||||
exp=$'(\n\t[5]=(\n\t\t[9]=(\n\t\t\t[2]=(\n\t\t\t\ttypeset -i x=36\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
exp=$'(\n\ttypeset -a [5]=(\n\t\ttypeset -a [9]=(\n\t\t\t[2]=(\n\t\t\t\ttypeset -i x=36\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
[[ $(print -v nar) == "$exp" ]] || err_exit 'read from a nameref variable from calling scope fails'
|
||||
}
|
||||
main
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ function m
|
|||
x_t c.x[4][5][8].field
|
||||
x_t x
|
||||
typeset -m c.x[4][6][9].field=x
|
||||
exp=$'(\n\ttypeset -C -a x=(\n\t\t[4]=(\n\t\t\t[5]=(\n\t\t\t\t[8]=(\n\t\t\t\t\tx_t field=(\n\t\t\t\t\t\thello=world\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\t[6]=(\n\t\t\t\t[9]=(\n\t\t\t\t\tx_t field=(\n\t\t\t\t\t\thello=world\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
exp=$'(\n\ttypeset -C -a x=(\n\t\ttypeset -a [4]=(\n\t\t\ttypeset -a [5]=(\n\t\t\t\t[8]=(\n\t\t\t\t\tx_t field=(\n\t\t\t\t\t\thello=world\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\ttypeset -a [6]=(\n\t\t\t\t[9]=(\n\t\t\t\t\tx_t field=(\n\t\t\t\t\t\thello=world\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t)\n\t)\n)'
|
||||
[[ $(print -v c) == "$exp" ]] || err_exit "typeset -m c.x[4][6][9].field=x where x is a type is not working"
|
||||
}
|
||||
m
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue