@@ -231,22 +231,33 @@ jobs:
231231 done <<< "$CURRENT_VARS"
232232 fi
233233
234- # Build JSON for new vars
234+ # Build JSON for new vars using jq for proper escaping
235235 if [ -n "$(echo "$NEW_VARS" | tr -d '[:space:]')" ]; then
236236 HAS_NEW_ENV_VARS=true
237- ENV_VARS_JSON="{"
238- FIRST_VAR=true
237+ ENV_VARS_JSON="{}"
239238 for var in $NEW_VARS; do
240- # Extract value, remove surrounding quotes, then escape internal quotes
241- DEFAULT_VALUE=$(grep "^${var}=" "$FULL_ENV_FILE" | cut -d'=' -f2- | sed 's/^"//;s/"$//' | sed 's/"/\\"/g' || echo "")
242- if [ "$FIRST_VAR" = "true" ]; then
243- ENV_VARS_JSON="${ENV_VARS_JSON}\"${var}\":\"${DEFAULT_VALUE}\""
244- FIRST_VAR=false
239+ # Extract value after =, handle quoted values with inline comments
240+ RAW_LINE=$(grep "^${var}=" "$FULL_ENV_FILE" | head -1)
241+ RAW_VALUE="${RAW_LINE#*=}"
242+
243+ # If value starts with quote, extract only the quoted part (handles inline comments)
244+ if [[ "$RAW_VALUE" == \"* ]]; then
245+ # Remove leading quote and extract until closing quote
246+ RAW_VALUE="${RAW_VALUE#\"}"
247+ RAW_VALUE="${RAW_VALUE%%\"*}"
248+ elif [[ "$RAW_VALUE" == \'* ]]; then
249+ # Handle single quotes
250+ RAW_VALUE="${RAW_VALUE#\'}"
251+ RAW_VALUE="${RAW_VALUE%%\'*}"
245252 else
246- ENV_VARS_JSON="${ENV_VARS_JSON},\"${var}\":\"${DEFAULT_VALUE}\""
253+ # Unquoted value - strip inline comments (space + #)
254+ RAW_VALUE="${RAW_VALUE%% #*}"
255+ RAW_VALUE="${RAW_VALUE%% #*}" # tab + #
247256 fi
257+
258+ # Use jq to properly escape the value for JSON
259+ ENV_VARS_JSON=$(echo "$ENV_VARS_JSON" | jq --arg key "$var" --arg val "$RAW_VALUE" '. + {($key): $val}')
248260 done
249- ENV_VARS_JSON="${ENV_VARS_JSON}}"
250261 echo " New env vars: $NEW_VARS"
251262 fi
252263 fi
0 commit comments