Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding to yaml only encodes the first document to a string #2067

Open
mackaybe opened this issue Jun 12, 2024 · 2 comments
Open

Encoding to yaml only encodes the first document to a string #2067

mackaybe opened this issue Jun 12, 2024 · 2 comments
Labels

Comments

@mackaybe
Copy link

mackaybe commented Jun 12, 2024

Describe the bug
Encoding to yaml only encodes the first document to a string

Note that any how to questions should be posted in the discussion board and not raised as an issue.

Version of yq: 4.42.1
Operating system: osx or linux
Installed via: homebrew and manual build

Input Yaml

foo.yml:

build: no
data:
  test.yaml: |
    a: b
    type: plain
    ---
    c: d
    type: juicy
    ---
    e: f
    type: greenish

Command
The command you ran:

yq '.data."test.yaml" = (.data."test.yaml" | from_yaml | select(.type == "juicy").c = "DD" | to_yaml)' foo.yaml

Actual behavior

build: no
data:
  test.yaml: |
    a: b
    type: plain

Expected behavior

build: no
data:
  test.yaml: |
    a: b
    type: plain
    ---
    c: DD
    type: juicy
    ---
    e: f
    type: greenish

Additional context

I get the same result for this:

export manifests=$(yq '.data."test.yaml"' foo.yaml | yq 'select(.type == "juicy").c = "DD"')
yq '.data."test.yaml" = env(manifests)' foo.yaml

this works as expected

yq '.data."test.yaml"' foo.yaml | yq 'select(.type == "juicy").c = "DD" | to_yaml'
@mackaybe
Copy link
Author

4.44.1 has same issue on osx

@mikefarah
Copy link
Owner

Verified - needs fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants