From 1849ef21e2ffe5bf5f08fdde91880ac60ef06245 Mon Sep 17 00:00:00 2001 From: Arpit Gupta Date: Sat, 2 May 2026 00:04:28 +0530 Subject: [PATCH] wcurl: fix missing argument crash for options --- tests/tests.sh | 11 +++++++++++ wcurl | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/tests/tests.sh b/tests/tests.sh index 5c03269..a7b35a1 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -273,5 +273,16 @@ testFragmentStripping() assertContains "Verify whether 'wcurl' correctly strips #fragments from filenames" "${ret}" '--output document.pdf ' } +testMissingArgumentError() +{ + ret=$(${WCURL_CMD} --curl-options 2>&1) + assertFalse "Verify whether 'wcurl' with missing argument exits with an error" "$?" + assertEquals "Verify whether 'wcurl' displays missing argument error for --curl-options" "${ret}" "Option '--curl-options' requires an argument." + + ret=$(${WCURL_CMD} -o 2>&1) + assertFalse "Verify whether 'wcurl' with missing argument exits with an error" "$?" + assertEquals "Verify whether 'wcurl' displays missing argument error for -o" "${ret}" "Option '-o' requires an argument." +} + # shellcheck disable=SC1091 . shunit2 diff --git a/wcurl b/wcurl index ab81b73..6e6908f 100755 --- a/wcurl +++ b/wcurl @@ -283,6 +283,9 @@ while [ -n "${1-}" ]; do ;; --curl-options) + if [ -z "${2-}" ]; then + error "Option '${1}' requires an argument." + fi shift CURL_OPTIONS="${CURL_OPTIONS} ${1}" ;; @@ -298,6 +301,9 @@ while [ -n "${1-}" ]; do ;; -o | -O | --output) + if [ -z "${2-}" ]; then + error "Option '${1}' requires an argument." + fi shift HAS_USER_SET_OUTPUT="true" OUTPUT_PATH="${1}"