lib: Fix 'getargs' setting an empty string when no args are left

This commit is contained in:
Ethan P 2021-04-03 17:16:15 -07:00
parent e4e916c63b
commit 650845dee4
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
2 changed files with 12 additions and 2 deletions

View File

@ -61,7 +61,11 @@ getargs() {
eval "$2=(\"\${$2[@]}\" $(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
fi
else
if [[ "${_ARGV_INDEX}" -ne "$((_ARGV_LAST+1))" ]]; then
eval "$1=($(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
else
eval "$1=()"
fi
fi
}

View File

@ -414,6 +414,12 @@ test:fn_getargs() {
# Ensure getargs doesn't remove remaining arguments.
shiftopt
assert_opt_name "three"
# Ensure it doesn't set an empty string.
args=(one two)
setargs
getargs args
assert_equal 0 "${#args[@]}"
}
test:fn_getargs_append() {