From 6b68de17e95250b61b7b7f2e0165d11eef93c985 Mon Sep 17 00:00:00 2001 From: C-Duv <1466273+C-Duv@users.noreply.github.com> Date: Thu, 2 Jan 2020 00:41:42 +0100 Subject: [PATCH] [Shell] fix(http): URL-encode message parameter Message was not URL-encoded when sent (as "msg" URI parameter) which could cause issues with some messages (because of spaces). This commits uses cURL's "--data-urlencode" option for "msg" parameter so that cURL does the encoding for us. As a consequence, the script don't have to manually convert newlines (to $NEWLINE_CHAR) anymore: cURL also does that for us. --- send-notification.sh | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/send-notification.sh b/send-notification.sh index fb8af3e..862c6db 100644 --- a/send-notification.sh +++ b/send-notification.sh @@ -6,7 +6,7 @@ # # Auteur: DUVERGIER Claude (http://claude.duvergier.fr) # -# Nécessite: sed, sh et wget +# Nécessite: sh et wget # # Possible usages: see usage_help() @@ -140,14 +140,6 @@ FINAL_MESSAGE_TO_SEND="${MESSAGE_HEADER}${MESSAGE_TO_SEND}${MESSAGE_FOOTER}" # echo "Will send the following to ${USER_LOGIN}:" #DEBUG # echo "${FINAL_MESSAGE_TO_SEND}" #DEBUG -# Converts newlines to $NEWLINE_CHAR -FINAL_MESSAGE_TO_SEND=$(\ - echo -n "${FINAL_MESSAGE_TO_SEND}" | \ - sed '{:q;N;s/\n/'${NEWLINE_CHAR}'/g;t q}'\ -) -# echo "Newline encoded message:" #DEBUG -# echo "${FINAL_MESSAGE_TO_SEND}" #DEBUG - # Particularités de l'appel de curl et la/les options associées : # * Renvoi le code réponse HTTP uniquement : # --write-out "%{http_code}" --silent --output /dev/null @@ -160,7 +152,7 @@ HTTP_STATUS_CODE=$(\ --get "${SMSAPI_BASEURL}/${SMSAPI_SEND_ACTION}" \ --data "user=${USER_LOGIN}" \ --data "pass=${API_KEY}" \ - --data "msg=${FINAL_MESSAGE_TO_SEND}" \ + --data-urlencode "msg=${FINAL_MESSAGE_TO_SEND}" \ ) # Codes réponse HTTP possibles