mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-31 04:44:05 +02:00
Sanitize
This commit is contained in:
@@ -29,18 +29,21 @@ mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
|
|||||||
|
|
||||||
# Escape special characters using printf and enclose in double quotes
|
# Escape special characters using printf and enclose in double quotes
|
||||||
sanitize_variable() {
|
sanitize_variable() {
|
||||||
local raw="$1" # original value
|
local raw="$1" # original value
|
||||||
local escaped # value after printf %q
|
local escaped # value after printf %q
|
||||||
printf -v escaped '%q' "$raw"
|
# Check if the value is an array
|
||||||
|
if [[ "$raw" == \[* ]]; then
|
||||||
# If nothing changed, return the original.
|
echo "One of your options is an array, skipping"
|
||||||
[[ "$raw" == "$escaped" ]] && {
|
return
|
||||||
printf '%s' "$raw"
|
fi
|
||||||
return
|
printf -v escaped '%q' "$raw"
|
||||||
}
|
# If nothing changed, return the original.
|
||||||
|
if [[ "$raw" == "$escaped" ]]; then
|
||||||
# Otherwise protect the escaped string with double quotes.
|
printf '%s' "$raw"
|
||||||
printf '"%s"' "$escaped"
|
return
|
||||||
|
fi
|
||||||
|
# Otherwise protect the escaped string with double quotes.
|
||||||
|
printf '"%s"' "$escaped"
|
||||||
}
|
}
|
||||||
|
|
||||||
for KEYS in "${arr[@]}"; do
|
for KEYS in "${arr[@]}"; do
|
||||||
@@ -52,7 +55,6 @@ for KEYS in "${arr[@]}"; do
|
|||||||
else
|
else
|
||||||
# Sanitize variable
|
# Sanitize variable
|
||||||
VALUE=$(sanitize_variable "$VALUE")
|
VALUE=$(sanitize_variable "$VALUE")
|
||||||
|
|
||||||
# Continue for single values
|
# Continue for single values
|
||||||
line="${KEYS}=${VALUE}"
|
line="${KEYS}=${VALUE}"
|
||||||
# Check if secret
|
# Check if secret
|
||||||
|
|||||||
Reference in New Issue
Block a user