Rewrite urlencode implementation

This commit is contained in:
Zhong Lufan 2023-01-29 15:21:10 +08:00
parent 168ad13db3
commit 5be0482a1f
No known key found for this signature in database
GPG Key ID: BE2B3A1E76AD7D04
1 changed files with 14 additions and 4 deletions

View File

@ -111,10 +111,20 @@ _aliapi_signature_nonce() {
}
_aliapi_urlencode() {
local result
result=$(curl --get --silent --output /dev/null --write-out "%{url_effective}" --data-urlencode "=$1" "")
result="${result//+/%20}" # 替换 + 为 %20
echo "${result#*\?}"
if [[ ${LC_ALL:-X} != C ]]; then
LC_ALL=C _aliapi_urlencode "$@"
return $?
fi
local char string=$1
while [[ -n $string ]]; do
char=${string:0:1}
string=${string:1}
case $char in
[-._~0-9A-Za-z]) printf %c "$char";;
*) printf %%%02X "'$char";;
esac
done
echo
}
if [[ ${#BASH_SOURCE[@]} -eq 1 ]]; then