From 852be20e2f120a7f63b54d04a377f69417bba87b Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 8 Jul 2025 11:28:33 +0200 Subject: [PATCH] Sanitize --- .templates/00-global_var.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.templates/00-global_var.sh b/.templates/00-global_var.sh index 891831dd7..33816211d 100644 --- a/.templates/00-global_var.sh +++ b/.templates/00-global_var.sh @@ -29,18 +29,21 @@ mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") # Escape special characters using printf and enclose in double quotes sanitize_variable() { - local raw="$1" # original value - local escaped # value after printf %q - printf -v escaped '%q' "$raw" - - # If nothing changed, return the original. - [[ "$raw" == "$escaped" ]] && { - printf '%s' "$raw" - return - } - - # Otherwise protect the escaped string with double quotes. - printf '"%s"' "$escaped" + local raw="$1" # original value + local escaped # value after printf %q + # Check if the value is an array + if [[ "$raw" == \[* ]]; then + echo "One of your options is an array, skipping" + return + fi + printf -v escaped '%q' "$raw" + # If nothing changed, return the original. + if [[ "$raw" == "$escaped" ]]; then + printf '%s' "$raw" + return + fi + # Otherwise protect the escaped string with double quotes. + printf '"%s"' "$escaped" } for KEYS in "${arr[@]}"; do @@ -52,7 +55,6 @@ for KEYS in "${arr[@]}"; do else # Sanitize variable VALUE=$(sanitize_variable "$VALUE") - # Continue for single values line="${KEYS}=${VALUE}" # Check if secret