Skip to content

Commit 8a7c51a

Browse files
committed
fix: No longer error on set-string
Error was caused by testing if the string to set is a variable. This was changed to only be done for set-object and set-array
1 parent 65f894e commit 8a7c51a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pkg/lib/traverse-set.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ bash_object.traverse-set() {
1111
local filter="$3"
1212
local final_value="$4"
1313

14-
# TODO: test this
15-
if bash_object.ensure.variable_does_exist "$final_value"; then :; else
16-
return
14+
# TODO: test, old versions of bash
15+
if [[ ! -v 4 ]]; then
16+
bash_object.util.die 'ERROR_INTERNAL_MISCELLANEOUS' "final_value is empty"
17+
return
1718
fi
1819

1920
# Start traversing at the root object
@@ -57,6 +58,11 @@ bash_object.traverse-set() {
5758
# If we are at the last element in the query
5859
elif ((i+1 == ${#REPLIES[@]})); then
5960
if [ "$final_value_type" = object ]; then
61+
# TODO: test this
62+
if bash_object.ensure.variable_does_exist "$final_value"; then :; else
63+
return
64+
fi
65+
6066
local oldIFS="$IFS"
6167
IFS='_'
6268
local filter_stack_string="${filter_stack[*]}"
@@ -90,6 +96,11 @@ bash_object.traverse-set() {
9096
globel_object["$key"]="${object_to_copy_from["$key"]}"
9197
done
9298
elif [ "$final_value_type" = array ]; then
99+
# TODO: test this
100+
if bash_object.ensure.variable_does_exist "$final_value"; then :; else
101+
return
102+
fi
103+
93104
local oldIFS="$IFS"
94105
IFS='_'
95106
local filter_stack_string="${filter_stack[*]}"

tests/set.bats

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
load './util/init.sh'
44

55
@test "Error if random variable already exists" {
6+
declare -gA objj=()
7+
68
bash_object.util.generate_vobject_name() {
79
REPLY="some_other_var"
810
}
911
declare -g some_other_var=
1012

11-
run bash_object.traverse-set object 'OBJECT' '.obj' obj
13+
run bash_object.traverse-set object 'OBJECT' '.obj' objj
1214

1315
assert_failure
1416
assert_output -p 'ERROR_INTERNAL_MISCELLANEOUS'

0 commit comments

Comments
 (0)