Skip to content

Commit 1ff33f1

Browse files
committed
fix: unbound variable error in parse_data_provider_args with set -u
Fixed "unbound variable" error when accessing array elements with negative indices under set -u (nounset mode). Changed from using args[-1] to calculating the last index explicitly and using a positive index, which is compatible with strict error checking
1 parent e57ef9f commit 1ff33f1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/runner.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ function runner::parse_data_provider_args() {
122122
fi
123123

124124
# Try eval first (needed for $'...' from printf '%q'), unless metacharacters present
125-
if [[ "$has_metachar" == false ]] && eval "args=($input)" 2>/dev/null; then
125+
if [[ "$has_metachar" == false ]] && eval "args=($input)" 2>/dev/null && [[ ${#args[@]} -gt 0 ]]; then
126126
# Successfully parsed - remove sentinel if present
127-
if [[ ${#args[@]} -gt 0 && -z "${args[-1]}" ]]; then
128-
unset 'args[-1]'
127+
local last_idx=$((${#args[@]} - 1))
128+
if [[ -z "${args[$last_idx]}" ]]; then
129+
unset 'args[$last_idx]'
129130
fi
130131
# Print args and return early
131132
for arg in "${args[@]}"; do

0 commit comments

Comments
 (0)