From b70c9c59383e52a9871aa0b5b81af4190ffddcd9 Mon Sep 17 00:00:00 2001 From: Dalibor Pospisil Date: Mon, 25 Jan 2021 22:00:39 +0100 Subject: [PATCH] fixed quoted string handling The multiline quoted string was not handled correctly. Now, there's separate code for handling quotest strings. --- test.sh | 35 +++++++++++++++++++++++++++++++++++ ya.sh | 17 +++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/test.sh b/test.sh index f29d35a..ebedea3 100755 --- a/test.sh +++ b/test.sh @@ -556,6 +556,41 @@ declare -A expected=( check 0 "wrong dict item" +yaml_data=" +description: 'Bug summary: Rebase FAPOLICYD to the latest upstream version + + Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1817413 + + ' +relevancy: ' + distro < rhel-8: False + + distro < rhel-8.3: False + ' +relevancy2: ' + + distro < rhel-8: False + + + distro < rhel-8.3: False + + ' +" +declare -A expected=( +[description]='Bug summary: Rebase FAPOLICYD to the latest upstream version +Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1817413 +' +[relevancy]=' distro < rhel-8: False +distro < rhel-8.3: False ' +[relevancy2]=' +distro < rhel-8: False + +distro < rhel-8.3: False +' +) +DEBUG=1 check 0 "quoted string" + + echo _______________________________________________ [[ $overall_result -eq 0 ]] && { yashLog "overall result" "PASS " diff --git a/ya.sh b/ya.sh index 35b86b5..ccfd6c2 100644 --- a/ya.sh +++ b/ya.sh @@ -192,6 +192,7 @@ __INTERNAL_yash_sanitize_value() { yashLogError "syntax error - bad indentation" return 1 } + space=' ' buffer+="${space}${line:$indent}" while read -r line; do [[ "${line:0:$indent}" =~ ^[[:space:]]*$ ]] || { @@ -271,6 +272,22 @@ __INTERNAL_yash_sanitize_value() { item2+="$line" done <<< "$buffer2" [[ -n "$item2" && ! "$item2" =~ ^[[:space:]]*$ ]] && buffer+=$'\n'"$json_prefix$item2" + elif [[ "$line" =~ ^[[:space:]]*(\'|\") ]]; then #' + yashLogDebug "quoted string" + eval "${type_name}=text" + space=' ' + while :; do + [[ "$line" =~ ^[[:space:]]*(.*)$ ]] + line="${BASH_REMATCH[1]}" + [[ "$line" =~ ^(.*[^[:space:]]*)[[:space:]]*$ ]] + [[ -z "${BASH_REMATCH[1]}" ]] && { + [[ "$space" == " " ]] && space=$'\n' || space+=$'\n' + } || { + buffer+="${space}${BASH_REMATCH[1]}" + space=' ' + } + read -r line || break + done elif [[ "$line" =~ ^[[:space:]]*-([[:space:]]|$) || "$line" =~ ^[^:]*:([[:space:]]|$) ]]; then yashLogDebug "sub-structure" eval "${type_name}=struct"