diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-12 16:50:27 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-12 16:50:27 (EDT) |
commit | 735aca5b44e8d731463b8f04b850de2b4b3d2df7 (patch) | |
tree | 53df356dafaf0e1807b59755e349b44ea4966ff1 | |
parent | dfdfafd31f0cb408f731dce4abcab4dedfd51d48 (diff) |
*ob_[gs]et_*_parameter(): Make validation more immediately clear
-rw-r--r-- | lib/package.sh | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/lib/package.sh b/lib/package.sh index 99f7b76..5111341 100644 --- a/lib/package.sh +++ b/lib/package.sh @@ -227,12 +227,10 @@ ob_get_source_parameter() fi # Convert field name to uppercase and validate. - name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" - case "${name:- }" in - *[!A-Z0-9_]*) - return 125 - ;; + case "${name}" in *[!A-Za-z0-9-]* | '') + return 125 esac + name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" eval "printf '%s' \"\${_OB_SRCFIELD_${name}}\"" @@ -260,12 +258,10 @@ ob_get_binary_parameter() tr -dC 'A-Z0-9')" # Convert field name to uppercase and validate. - name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" - case "${name:- }" in - *[!A-Z0-9_]*) - return 125 - ;; + case "${name}" in *[!A-Za-z0-9-]* | '') + return 125 esac + name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" eval "printf '%s' \"\${_OB_BINFIELD_${package}_${name}}\"" @@ -357,12 +353,10 @@ _ob_set_source_parameter() value="${2}" # Convert field name to uppercase and validate. - name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" - case "${name:- }" in - *[!A-Z0-9_]*) - return 125 - ;; + case "${name}" in *[!A-Za-z0-9-]* | '') + return 125 esac + name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" _OB_SOURCE_PARAMETERS="${_OB_SOURCE_PARAMETERS} ${name}" @@ -390,12 +384,10 @@ _ob_set_binary_parameter() tr -dC 'A-Z0-9')" # Convert field name to uppercase and validate. - name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" - case "${name:- }" in - *[!A-Z0-9_]*) - return 125 - ;; + case "${name}" in *[!A-Za-z0-9-]* | '') + return 125 esac + name="$(echo "${name}" | tr 'a-z-' 'A-Z_')" if ! echo " ${_OB_BINARY_PARAMETERS} " | grep " ${name} " \ >/dev/null 2>&1; then |