@@ -11,6 +11,11 @@ bash_object.traverse-set() {
11
11
local filter=" $3 "
12
12
local final_value=" $4 "
13
13
14
+ # TODO: test this
15
+ if bash_object.ensure.variable_does_exist " $final_value " ; then : ; else
16
+ return
17
+ fi
18
+
14
19
# Start traversing at the root object
15
20
local current_object_name=" $root_object_name "
16
21
local -n current_object=" $root_object_name "
@@ -52,45 +57,69 @@ bash_object.traverse-set() {
52
57
# If we are at the last element in the query
53
58
elif (( i+ 1 == ${# REPLIES[@]} )) ; then
54
59
if [ " $final_value_type " = object ]; then
55
- bash_object.util.generate_vobject_name
56
- local new_current_object_name=" $REPLY "
60
+ local oldIFS=" $IFS "
61
+ IFS=' _'
62
+ local filter_stack_string=" ${filter_stack[*]} "
63
+ IFS=" $oldIFS "
57
64
58
- # TODO: double-check if new_current_object_name only has underscores, dots, etc. (printf %q?)
65
+ bash_object.util.generate_vobject_name " $root_object_name " " $filter_stack_string "
66
+ local global_object_name=" $REPLY "
59
67
60
- if (( BASH_VERSINFO[0 ] >= 5 )) || (( BASH_VERSINFO[0 ] == 4 && BASH_VERSINFO[1 ] >= 2 )) ; then
61
- if [[ -v " $new_current_object_name " ]]; then
62
- bash_object.util.die ' ERROR_INTERNAL_MISCELLANEOUS' " Autogenerated variable '$new_current_object_name ' already exists. Did RANDOM or SRANDOM get unset?"
63
- return
64
- fi
65
- else
66
- if ! eval "
67
- if ! [ -z \$ {$new_current_object_name +x} ]; then
68
- bash_object.util.die 'ERROR_INTERNAL_MISCELLANEOUS' \" Autogenerated variable '$new_current_object_name ' already exists. Did RANDOM or SRANDOM get unset?\"
69
- return
70
- fi
71
- " ; then
72
- bash_object.util.die ' ERROR_INTERNAL_MISCELLANEOUS' ' Eval unset test'
73
- return
74
- fi
68
+ if bash_object.ensure.variable_is_valid " $global_object_name " ; then : ; else
69
+ return
75
70
fi
76
71
77
- if ! eval " declare -gA $new_current_object_name =()" ; then
72
+ if bash_object.ensure.variable_does_not_exist " $global_object_name " ; then : ; else
73
+ return
74
+ fi
75
+
76
+ if ! eval " declare -gA $global_object_name =()" ; then
78
77
bash_object.util.die ' ERROR_INTERNAL_MISCELLANEOUS' ' Eval declare failed'
79
78
return
80
79
fi
81
80
82
- local -n new_current_object=" $new_current_object_name "
81
+ current_object[" $key " ]=$' \x1C\x1D ' " type=object;&$global_object_name "
82
+
83
+ local -n globel_object=" $global_object_name "
84
+ local -n object_to_copy_from=" $final_value "
83
85
84
- current_object[ " $key " ]= $' \x1C\x1D ' " type=object;& $new_current_object_name "
86
+ # TODO: test if object_to_copy is of the correct type
85
87
86
- local -n object_to_copy=" $final_value "
87
- # test if the object_to_copy is of the right type
88
- for key in " ${! object_to_copy[@]} " ; do
89
- new_current_object[" $key " ]=" ${object_to_copy["$key"]} "
88
+ for key in " ${! object_to_copy_from[@]} " ; do
89
+ # shellcheck disable=SC2034
90
+ globel_object[" $key " ]=" ${object_to_copy_from["$key"]} "
90
91
done
91
92
elif [ " $final_value_type " = array ]; then
92
- :
93
- # current_object["$key"]=("${new_array[@]}")
93
+ local oldIFS=" $IFS "
94
+ IFS=' _'
95
+ local filter_stack_string=" ${filter_stack[*]} "
96
+ IFS=" $oldIFS "
97
+
98
+ bash_object.util.generate_vobject_name " $root_object_name " " $filter_stack_string "
99
+ local global_array_name=" $REPLY "
100
+
101
+ if bash_object.ensure.variable_is_valid " $global_array_name " ; then : ; else
102
+ return
103
+ fi
104
+
105
+ if bash_object.ensure.variable_does_not_exist " $global_array_name " ; then : ; else
106
+ return
107
+ fi
108
+
109
+ if ! eval " declare -ga $global_array_name =()" ; then
110
+ bash_object.util.die ' ERROR_INTERNAL_MISCELLANEOUS' ' Eval declare failed'
111
+ return
112
+ fi
113
+
114
+ current_object[" $key " ]=$' \x1C\x1D ' " type=array;&$global_array_name "
115
+
116
+ local -n global_array=" $global_array_name "
117
+ local -n array_to_copy_from=" $final_value "
118
+
119
+ # TODO: test if object_to_copy is of the correct type
120
+
121
+ # shellcheck disable=SC2034
122
+ global_array=(" ${array_to_copy_from[@]} " )
94
123
elif [ " $final_value_type " = string ]; then
95
124
current_object[" $key " ]=" $final_value "
96
125
else
0 commit comments