From d2a136be3c948c4ec5ab4c4983e6be46afff9545 Mon Sep 17 00:00:00 2001 From: myvesta <38690722+myvesta@users.noreply.github.com> Date: Fri, 25 Apr 2025 14:45:45 +0200 Subject: [PATCH] parse_object_kv_list_non_eval() --- func/main.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/func/main.sh b/func/main.sh index 7397dec4..2302842e 100644 --- a/func/main.sh +++ b/func/main.sh @@ -1160,6 +1160,7 @@ check_if_service_exists() { parse_object_kv_list_non_eval() { # Let's combine all the parameters into one string, replace the new lines with a space local str="${*//$'\n'/ }" + local backup_str=$str # Escape " and $ # str="${str//\"/\\\"}" # str="${str//\$/\\\$}" @@ -1187,4 +1188,32 @@ parse_object_kv_list_non_eval() { # Let's remove the processed part from str to continue str="${str#*$match}" done + + if [ -z "$PARSE_DOUBLE_QUOTES_VAR" ]; then + return; + fi + + str=$backup_str + # Loop until we find the next key="value" + while [[ $str =~ ([A-Za-z][[:alnum:]_]*)=\"([^\"]*)\" ]]; do + key="${BASH_REMATCH[1]}" + val="${BASH_REMATCH[2]}" + match="${BASH_REMATCH[0]}" + + # Key validation: alphanumeric, length 2–66 (key must start and end with a letter/number) + if ! [[ "$key" =~ ^[[:alnum:]][_[:alnum:]]{0,64}[[:alnum:]]$ ]]; then + check_result "$E_INVALID" "Invalid key format [$key]" + fi + + # Value validation: must not contain an apostrophe + if ! [[ "$val" =~ ^[^\']*$ ]]; then + check_result "$E_INVALID" "Invalid value format [$val]" + fi + + # Declaring a global variable + declare -g "$key"="$val" + + # Let's remove the processed part from str to continue + str="${str#*$match}" + done }