Skip to content

Commit

Permalink
[BUGFIX] Fix --share flag when used with emails | Resolve labbots#149
Browse files Browse the repository at this point in the history
* also fix a bug in email validation regex
  • Loading branch information
Akianonymus committed May 9, 2021
1 parent 1302aba commit f11ff9d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 36 deletions.
6 changes: 3 additions & 3 deletions bash/drive-utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ _full_upload() {
###################################################
_share_id() {
[[ $# -lt 2 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
declare id="${1}" share_email="${2}" role="reader" type="${share_email:+user}"
declare type share_post_data share_post_data share_response
declare id="${1}" share_email="${2}" role="reader"
declare type="${share_email:+user}" share_post_data share_post_data share_response

"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
share_post_data="{\"role\":\"${role}\",\"type\":\"${type:-anyone}\"${share_email:+,\\\"emailAddress\\\":\\\"${share_email}\\\"}}"
share_post_data="{\"role\":\"${role}\",\"type\":\"${type:-anyone}\"${share_email:+,\"emailAddress\":\"${share_email}\"}}"

share_response="$(_api_request "${CURL_PROGRESS_EXTRA}" \
-X POST \
Expand Down
18 changes: 8 additions & 10 deletions bash/release/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -1279,11 +1279,11 @@ _full_upload() {
###################################################
_share_id() {
[[ $# -lt 2 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
declare id="${1}" share_email="${2}" role="reader" type="${share_email:+user}"
declare type share_post_data share_post_data share_response
declare id="${1}" share_email="${2}" role="reader"
declare type="${share_email:+user}" share_post_data share_post_data share_response

"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
share_post_data="{\"role\":\"${role}\",\"type\":\"${type:-anyone}\"${share_email:+,\\\"emailAddress\\\":\\\"${share_email}\\\"}}"
share_post_data="{\"role\":\"${role}\",\"type\":\"${type:-anyone}\"${share_email:+,\"emailAddress\":\"${share_email}\"}}"

share_response="$(_api_request "${CURL_PROGRESS_EXTRA}" \
-X POST \
Expand Down Expand Up @@ -1595,7 +1595,7 @@ _cleanup_config() {
# Success - Set all the variables
# Error - Print error message and exit
# Reference:
# Email Regex - https://stackoverflow.com/a/57295993
# Email Regex - https://gist.github.com/guessi/82a73ee7eb2b1216eb9db17bb8d65dd1
###################################################
_setup_arguments() {
[[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
Expand Down Expand Up @@ -1696,12 +1696,10 @@ _setup_arguments() {
;;
-S | --share)
SHARE="_share_id"
EMAIL_REGEX="^([A-Za-z]+[A-Za-z0-9]*\+?((\.|\-|\_)?[A-Za-z]+[A-Za-z0-9]*)*)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
[[ -n ${1} && ! ${1} = -* ]] && SHARE_EMAIL="${2}" && {
! [[ ${SHARE_EMAIL} =~ ${EMAIL_REGEX} ]] && printf "\nError: Provided email address for share option is invalid.\n" && exit 1
shift
}
export SHARE_EMAIL
EMAIL_REGEX="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
if [[ -n ${2} && ! ${2} = -* && ${2} =~ ${EMAIL_REGEX} ]]; then
SHARE_EMAIL="${2}" && shift && export SHARE_EMAIL
fi
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down
12 changes: 5 additions & 7 deletions bash/upload.bash
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ _cleanup_config() {
# Success - Set all the variables
# Error - Print error message and exit
# Reference:
# Email Regex - https://stackoverflow.com/a/57295993
# Email Regex - https://gist.github.com/guessi/82a73ee7eb2b1216eb9db17bb8d65dd1
###################################################
_setup_arguments() {
[[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
Expand Down Expand Up @@ -209,12 +209,10 @@ _setup_arguments() {
;;
-S | --share)
SHARE="_share_id"
EMAIL_REGEX="^([A-Za-z]+[A-Za-z0-9]*\+?((\.|\-|\_)?[A-Za-z]+[A-Za-z0-9]*)*)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
[[ -n ${1} && ! ${1} = -* ]] && SHARE_EMAIL="${2}" && {
! [[ ${SHARE_EMAIL} =~ ${EMAIL_REGEX} ]] && printf "\nError: Provided email address for share option is invalid.\n" && exit 1
shift
}
export SHARE_EMAIL
EMAIL_REGEX="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
if [[ -n ${2} && ! ${2} = -* && ${2} =~ ${EMAIL_REGEX} ]]; then
SHARE_EMAIL="${2}" && shift && export SHARE_EMAIL
fi
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down
2 changes: 1 addition & 1 deletion sh/drive-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ _share_id() {
unset post_data_share_id response_share_id
"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
post_data_share_id="{\"role\":\"${role_share_id}\",\"type\":\"${type_share_id:-anyone}\"${share_email_share_id:+,\\\"emailAddress\\\":\\\"${share_email_share_id}\\\"}}"
post_data_share_id="{\"role\":\"${role_share_id}\",\"type\":\"${type_share_id:-anyone}\"${share_email_share_id:+,\"emailAddress\":\"${share_email_share_id}\"}}"
response_share_id="$(_api_request "${CURL_PROGRESS_EXTRA}" \
-X POST \
Expand Down
15 changes: 7 additions & 8 deletions sh/release/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ _share_id() {
unset post_data_share_id response_share_id
"${EXTRA_LOG}" "justify" "Sharing.." "-" 1>&2
post_data_share_id="{\"role\":\"${role_share_id}\",\"type\":\"${type_share_id:-anyone}\"${share_email_share_id:+,\\\"emailAddress\\\":\\\"${share_email_share_id}\\\"}}"
post_data_share_id="{\"role\":\"${role_share_id}\",\"type\":\"${type_share_id:-anyone}\"${share_email_share_id:+,\"emailAddress\":\"${share_email_share_id}\"}}"
response_share_id="$(_api_request "${CURL_PROGRESS_EXTRA}" \
-X POST \
Expand Down Expand Up @@ -1524,7 +1524,7 @@ EOF
# Success - Set all the variables
# Error - Print error message and exit
# Reference:
# Email Regex - https://stackoverflow.com/a/57295993
# Email Regex - https://gist.github.com/guessi/82a73ee7eb2b1216eb9db17bb8d65dd1
###################################################
_setup_arguments() {
[ $# = 0 ] && printf "Missing arguments\n" && return 1
Expand Down Expand Up @@ -1627,16 +1627,15 @@ _setup_arguments() {
;;
-S | --share)
SHARE="_share_id"
EMAIL_REGEX="^([A-Za-z]+[A-Za-z0-9]*\+?((\.|\-|\_)?[A-Za-z]+[A-Za-z0-9]*)*)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
case "${1}" in
EMAIL_REGEX="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
case "${2}" in
-* | '') : ;;
*)
SHARE_EMAIL="${2}"
printf "%s\n" "${SHARE_EMAIL}" | grep -qE "${EMAIL_REGEX}" || printf "\nError: Provided email address for share option is invalid.\n" && exit 1
shift
if printf "%s\n" "${2}" | grep -qE "${EMAIL_REGEX}"; then
SHARE_EMAIL="${2}" && shift && export SHARE_EMAIL
fi
;;
esac
export SHARE_EMAIL
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down
13 changes: 6 additions & 7 deletions sh/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ EOF
# Success - Set all the variables
# Error - Print error message and exit
# Reference:
# Email Regex - https://stackoverflow.com/a/57295993
# Email Regex - https://gist.github.com/guessi/82a73ee7eb2b1216eb9db17bb8d65dd1
###################################################
_setup_arguments() {
[ $# = 0 ] && printf "Missing arguments\n" && return 1
Expand Down Expand Up @@ -213,16 +213,15 @@ _setup_arguments() {
;;
-S | --share)
SHARE="_share_id"
EMAIL_REGEX="^([A-Za-z]+[A-Za-z0-9]*\+?((\.|\-|\_)?[A-Za-z]+[A-Za-z0-9]*)*)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
case "${1}" in
EMAIL_REGEX="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
case "${2}" in
-* | '') : ;;
*)
SHARE_EMAIL="${2}"
printf "%s\n" "${SHARE_EMAIL}" | grep -qE "${EMAIL_REGEX}" || printf "\nError: Provided email address for share option is invalid.\n" && exit 1
shift
if printf "%s\n" "${2}" | grep -qE "${EMAIL_REGEX}"; then
SHARE_EMAIL="${2}" && shift && export SHARE_EMAIL
fi
;;
esac
export SHARE_EMAIL
;;
--speed)
_check_longoptions "${1}" "${2}"
Expand Down

0 comments on commit f11ff9d

Please sign in to comment.