Skip to content

Commit e717b90

Browse files
committed
fix: Test for varable existance properly works
1 parent bf4d1d5 commit e717b90

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pkg/lib/traverse-set.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bash_object.traverse-set() {
5151
if [ "$final_value_type" = object ]; then
5252
# TODO: test this
5353
# shellcheck disable=SC1087
54-
if bash_object.ensure.variable_does_exist "$final_value[@]"; then :; else
54+
if bash_object.ensure.variable_does_exist "$final_value"; then :; else
5555
return
5656
fi
5757

@@ -85,7 +85,7 @@ bash_object.traverse-set() {
8585
elif [ "$final_value_type" = array ]; then
8686
# TODO: test this
8787
# shellcheck disable=SC1087
88-
if bash_object.ensure.variable_does_exist "$final_value[@]"; then :; else
88+
if bash_object.ensure.variable_does_exist "$final_value"; then :; else
8989
return
9090
fi
9191

pkg/lib/util/ensure.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ bash_object.ensure.variable_is_valid() {
55
return 0
66
}
77

8-
# @description Ensure the variable already exists. Note that the variable _must_ be sanitized before using this function
8+
# @description Ensure the variable already exists
99
bash_object.ensure.variable_does_exist() {
1010
local variable_name="$1"
1111

@@ -14,14 +14,9 @@ bash_object.ensure.variable_does_exist() {
1414
return
1515
fi
1616

17-
if ((BASH_VERSINFO[0] >= 5)) || ((BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 2)); then
18-
if [[ ! -v "$variable_name" ]]; then
19-
bash_object.util.die 'ERROR_INTERNAL_MISCELLANEOUS' "Variable '$variable_name' does not exist, but it should"
17+
if ! declare -p "$variable_name" &>/dev/null; then
18+
bash_object.util.die 'ERROR_INTERNAL_MISCELLANEOUS' "Variable '$variable_name' does not exist, but it should"
2019
return
21-
fi
22-
else
23-
# TODO
24-
:
2520
fi
2621
}
2722

0 commit comments

Comments
 (0)