libmakepkg: fix empty arguments in parseopts
Previously parseopts checked if there was an argument by checking that the string was non-empty, resulting in empty arguments being incorrectly considered non-existent. This change makes parseopts check if arguments exist at all, rather than checking that they are non-empty Signed-off-by: Ethan Sommer <e5ten.arch@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
091b244d0f
commit
1bfae7d14a
2 changed files with 8 additions and 5 deletions
|
@ -103,7 +103,7 @@ parseopts() {
|
||||||
OPTRET+=("-$opt" "${1:i+1}")
|
OPTRET+=("-$opt" "${1:i+1}")
|
||||||
break
|
break
|
||||||
# if we're at the end, grab the the next positional, if it exists
|
# if we're at the end, grab the the next positional, if it exists
|
||||||
elif (( i == ${#1} - 1 )) && [[ $2 ]]; then
|
elif (( i == ${#1} - 1 && $# > 1 )); then
|
||||||
OPTRET+=("-$opt" "$2")
|
OPTRET+=("-$opt" "$2")
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
|
@ -144,7 +144,7 @@ parseopts() {
|
||||||
case $? in
|
case $? in
|
||||||
0)
|
0)
|
||||||
# parse failure
|
# parse failure
|
||||||
if [[ $optarg ]]; then
|
if [[ $1 = *=* ]]; then
|
||||||
printf "${0##*/}: $(gettext "option '%s' does not allow an argument")\n" "--$opt" >&2
|
printf "${0##*/}: $(gettext "option '%s' does not allow an argument")\n" "--$opt" >&2
|
||||||
OPTRET=(--)
|
OPTRET=(--)
|
||||||
return 1
|
return 1
|
||||||
|
@ -155,10 +155,10 @@ parseopts() {
|
||||||
;;
|
;;
|
||||||
1)
|
1)
|
||||||
# --longopt=optarg
|
# --longopt=optarg
|
||||||
if [[ $optarg ]]; then
|
if [[ $1 = *=* ]]; then
|
||||||
OPTRET+=("--$opt" "$optarg")
|
OPTRET+=("--$opt" "$optarg")
|
||||||
# --longopt optarg
|
# --longopt optarg
|
||||||
elif [[ $2 ]]; then
|
elif (( $# > 1 )); then
|
||||||
OPTRET+=("--$opt" "$2" )
|
OPTRET+=("--$opt" "$2" )
|
||||||
shift
|
shift
|
||||||
# parse failure
|
# parse failure
|
||||||
|
|
|
@ -31,7 +31,7 @@ tap_parse() {
|
||||||
unset OPTRET
|
unset OPTRET
|
||||||
}
|
}
|
||||||
|
|
||||||
tap_plan 54
|
tap_plan 56
|
||||||
|
|
||||||
# usage: tap_parse <expected result> <token count> test-params...
|
# usage: tap_parse <expected result> <token count> test-params...
|
||||||
# a failed tap_parse will match only the end of options marker '--'
|
# a failed tap_parse will match only the end of options marker '--'
|
||||||
|
@ -117,4 +117,7 @@ tap_parse '--opt= --opt=foo --opt --' 4 --opt= --opt=foo --opt
|
||||||
# short opt with and without optional arg, and non-option arg
|
# short opt with and without optional arg, and non-option arg
|
||||||
tap_parse '-b=foo -A -b -- foo' 5 -bfoo -Ab foo
|
tap_parse '-b=foo -A -b -- foo' 5 -bfoo -Ab foo
|
||||||
|
|
||||||
|
# all possible ways to specify empty optargs
|
||||||
|
tap_parse '--key --pkg -p --' 7 --key '' --pkg='' -p ''
|
||||||
|
|
||||||
tap_finish
|
tap_finish
|
||||||
|
|
Loading…
Add table
Reference in a new issue