1
1
# shellcheck shell=bash
2
2
3
3
bash_object.traverse-get () {
4
- REPLY=
4
+ unset REPLY
5
5
6
6
if [ -n " ${TRACE_BASH_OBJECT_TRAVERSE+x} " ]; then
7
7
stdtrace.log 0 ' '
@@ -26,10 +26,17 @@ bash_object.traverse-get() {
26
26
esac
27
27
for (( i= 0 ; i< ${# REPLIES[@]} ; i++ )) ; do
28
28
local key=" ${REPLIES[$i]} "
29
+ local is_index_of_array=' no'
30
+
29
31
filter_stack+=(" $key " )
30
32
31
33
bash_object.trace_loop
32
34
35
+ if [ " ${key:: 1} " = $' \x1C ' ]; then
36
+ key=" ${key# ?} "
37
+ is_index_of_array=' yes'
38
+ fi
39
+
33
40
# If 'key' is not a member of object or index of array, error
34
41
if [ -z " ${current_object["$key"]+x} " ]; then
35
42
echo " Error: Key '$key ' is not in object '$current_object_name '"
@@ -54,9 +61,27 @@ bash_object.traverse-get() {
54
61
local -n current_object=" $current_object_name "
55
62
56
63
if (( i+ 1 < ${# REPLIES[@]} )) ; then
57
- # Do nothing, we have already set 'current_object'
64
+ # TODO: test these internal invalid errors
65
+ # Do nothing (assuming the type is correct), we have already set 'current_object'
58
66
# for the next iteration
59
- :
67
+ case " $vmd_dtype " in
68
+ object)
69
+ if [ " $is_index_of_array " = yes ]; then
70
+ bash_object.util.traverse_fail ' ERROR_INTERNAL_INVALID_VOBJ' " Expected object, but reference to array was found"
71
+ return
72
+ fi
73
+ ;;
74
+ array)
75
+ if [ " $is_index_of_array " = no ]; then
76
+ bash_object.util.traverse_fail ' ERROR_INTERNAL_INVALID_VOBJ' " Expected array, but reference to object was found"
77
+ return
78
+ fi
79
+ ;;
80
+ * )
81
+ bash_object.util.traverse_fail ' ERROR_INTERNAL_INVALID_VOBJ' " vmd_dtype: $vmd_dtype "
82
+ return
83
+ ;;
84
+ esac
60
85
elif (( i+ 1 == ${# REPLIES[@]} )) ; then
61
86
# We are last element of query, return the object
62
87
if [ " $final_value_type " = object ]; then
@@ -80,6 +105,7 @@ bash_object.traverse-get() {
80
105
return
81
106
;;
82
107
array)
108
+ declare -ga REPLY=()
83
109
local key=
84
110
for key in " ${! current_object[@]} " ; do
85
111
REPLY[" $key " ]=" ${current_object["$key"]} "
@@ -136,7 +162,7 @@ bash_object.traverse-get() {
136
162
137
163
bash_object.trace_current_object
138
164
if [ -n " ${TRACE_BASH_OBJECT_TRAVERSE+x} " ]; then
139
- stdtrace.log 1 " END BLOCK"
165
+ stdtrace.log 0 " END BLOCK"
140
166
fi
141
167
fi
142
168
done
0 commit comments