Skip to content

Commit

Permalink
fixed quoted string handling
Browse files Browse the repository at this point in the history
The multiline quoted string was not handled correctly.

Now, there's separate code for handling quotest strings.
  • Loading branch information
sopos committed Jan 25, 2021
1 parent d7e5cb6 commit b70c9c5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
17 changes: 17 additions & 0 deletions ya.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:]]*$ ]] || {
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b70c9c5

Please sign in to comment.