From 7dd4c1dd2408c021e59689f2748783b6bf7c74d0 Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Fri, 4 Jul 2025 04:39:06 -0600 Subject: [PATCH] fix: url encode envs in static-env-handler. Fixes #122. --- static-env-handler.sh | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) mode change 100644 => 100755 static-env-handler.sh diff --git a/static-env-handler.sh b/static-env-handler.sh old mode 100644 new mode 100755 index 247c0e5..0a6ddf1 --- a/static-env-handler.sh +++ b/static-env-handler.sh @@ -4,22 +4,27 @@ set -eu ROOT="/usr/share/nginx/html" QS="" +# URL encode a string +url_encode() { + local string="$1" + printf '%s' "$string" | sed 's/ /%20/g; s/"/%22/g; s//%3E/g; s/&/%26/g; s/#/%23/g; s/+/%2B/g' +} + # build query string from WSQS_ env vars -for var in $(env); do - case "$var" in - WSQS_*=*) - key="${var%%=*}" - val="${var#*=}" - key="${key#WSQS_}" - key="${key//_/-}" - if [ -n "$QS" ]; then - QS="$QS&${key}=${val}" - else - QS="${key}=${val}" - fi - ;; - esac -done +while IFS='=' read -r key val; do + # Remove WSQS_ prefix and convert underscores to hyphens + key="${key#WSQS_}" + key="${key//_/-}" + # URL encode the value + encoded_val=$(url_encode "$val") + if [ -n "$QS" ]; then + QS="$QS&${key}=${encoded_val}" + else + QS="${key}=${encoded_val}" + fi +done << EOF +$(env | grep '^WSQS_') +EOF if [ -n "$QS" ]; then