Skip to content

use yq.strenv() to handle multiline env values#104

Merged
patrickcrocker merged 1 commit intonulldriver:mainfrom
hdisysteme:fix/multiline-env-vars
May 28, 2023
Merged

use yq.strenv() to handle multiline env values#104
patrickcrocker merged 1 commit intonulldriver:mainfrom
hdisysteme:fix/multiline-env-vars

Conversation

@wanddynosios
Copy link
Copy Markdown
Contributor

Problem description

When upgrading from yq 3.x to 4.x, the behaviour regarding multiline changed.

Steps to reproduce

Setup

user@pc:/# cat test.sh
#!/bin/bash
yq --version
echo """---
applications:
  - env:
""" > manifest.yml

export manifest="manifest.yml"
export key="MYKEY"
export value='{
    "glossary": {
        "title": "example glossary",
    }
}'
echo "WRONG:"
yq '.env[env(key)] = env(value)' "$manifest"

echo "CORRECT:"
yq '.env[env(key)] = strenv(value)' "$manifest"

Result

yq (https://github.com/mikefarah/yq/) version v4.30.6
WRONG:
---
applications:
  - env:
env:
  MYKEY: {"glossary": {"title": "example glossary"}}
CORRECT:
---
applications:
  - env:
env:
  MYKEY: |-
    {
        "glossary": {
            "title": "example glossary",
        }
    }

Especially when working with YAML and other newline-sensitive formats this is essential.

Fix

Use yq.strenv() instead of yq.env()

@patrickcrocker patrickcrocker merged commit dfdfa36 into nulldriver:main May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants