Enhance unquoting logic in secrets generation script

- Updated the unquoting mechanism in 03_generate_secrets.sh to repeatedly remove surrounding quotes from variable values, improving the handling of quoted strings and ensuring accurate environment variable assignment.
This commit is contained in:
Yury Kossakovsky
2025-05-11 16:29:19 -06:00
parent 000a1ae472
commit 4737b5b950

View File

@@ -54,10 +54,20 @@ if [ -f "$OUTPUT_FILE" ]; then
if [[ -n "$line" && ! "$line" =~ ^\\s*# && "$line" == *"="* ]]; then
varName=$(echo "$line" | cut -d'=' -f1 | xargs)
varValue=$(echo "$line" | cut -d'=' -f2-)
# Simple unquote for "value" or 'value'
if [[ "$varValue" =~ ^\\"(.*)\\"$ || "$varValue" =~ ^\\'(.*)\\'$ ]]; then
varValue="${BASH_REMATCH[1]}"
fi
# Repeatedly unquote "value" or 'value' to get the bare value
_tempVal="$varValue"
while true; do
if [[ "$_tempVal" =~ ^\"(.*)\"$ ]]; then # Check double quotes
_tempVal="${BASH_REMATCH[1]}"
continue
fi
if [[ "$_tempVal" =~ ^\'(.*)\'$ ]]; then # Check single quotes
_tempVal="${BASH_REMATCH[1]}"
continue
fi
break # No more surrounding quotes of these types
done
varValue="$_tempVal"
existing_env_vars["$varName"]="$varValue"
fi
done < "$OUTPUT_FILE"