mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-08-07 21:52:29 +02:00
Update 00-global_var.sh
This commit is contained in:
@@ -29,21 +29,18 @@ 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"
|
||||||
local escaped # value after printf %q
|
local escaped
|
||||||
# Check if the value is an array
|
|
||||||
if [[ "$raw" == \[* ]]; then
|
if [[ "$raw" == \[* ]]; then
|
||||||
echo "One of your options is an array, skipping"
|
echo "One of your options is an array, skipping"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
printf -v escaped '%q' "$raw"
|
printf -v escaped '%q' "$raw"
|
||||||
# If nothing changed, return the original.
|
|
||||||
if [[ "$raw" == "$escaped" ]]; then
|
if [[ "$raw" == "$escaped" ]]; then
|
||||||
printf '%s' "$raw"
|
printf '%s' "$raw"
|
||||||
return
|
else
|
||||||
|
printf '%s' "$escaped"
|
||||||
fi
|
fi
|
||||||
# Otherwise protect the escaped string with double quotes.
|
|
||||||
printf '"%s"' "$escaped"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for KEYS in "${arr[@]}"; do
|
for KEYS in "${arr[@]}"; do
|
||||||
|
|||||||
Reference in New Issue
Block a user