mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 11:39:30 -07:00
Merge pull request #123 from rmitchellscott/fix-static-envs
fix: url encode envs in static-env-handler. Fixes #122.
This commit is contained in:
35
static-env-handler.sh
Normal file → Executable file
35
static-env-handler.sh
Normal file → Executable file
@@ -4,22 +4,27 @@ set -eu
|
|||||||
ROOT="/usr/share/nginx/html"
|
ROOT="/usr/share/nginx/html"
|
||||||
QS=""
|
QS=""
|
||||||
|
|
||||||
|
# URL encode a string
|
||||||
|
url_encode() {
|
||||||
|
local string="$1"
|
||||||
|
printf '%s' "$string" | sed 's/ /%20/g; s/"/%22/g; s/</%3C/g; s/>/%3E/g; s/&/%26/g; s/#/%23/g; s/+/%2B/g'
|
||||||
|
}
|
||||||
|
|
||||||
# build query string from WSQS_ env vars
|
# build query string from WSQS_ env vars
|
||||||
for var in $(env); do
|
while IFS='=' read -r key val; do
|
||||||
case "$var" in
|
# Remove WSQS_ prefix and convert underscores to hyphens
|
||||||
WSQS_*=*)
|
key="${key#WSQS_}"
|
||||||
key="${var%%=*}"
|
key="${key//_/-}"
|
||||||
val="${var#*=}"
|
# URL encode the value
|
||||||
key="${key#WSQS_}"
|
encoded_val=$(url_encode "$val")
|
||||||
key="${key//_/-}"
|
if [ -n "$QS" ]; then
|
||||||
if [ -n "$QS" ]; then
|
QS="$QS&${key}=${encoded_val}"
|
||||||
QS="$QS&${key}=${val}"
|
else
|
||||||
else
|
QS="${key}=${encoded_val}"
|
||||||
QS="${key}=${val}"
|
fi
|
||||||
fi
|
done << EOF
|
||||||
;;
|
$(env | grep '^WSQS_')
|
||||||
esac
|
EOF
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$QS" ]; then
|
if [ -n "$QS" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user