mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
11.25k stars 564 forks source link

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

Open mackaybe opened 3 weeks ago

mackaybe commented 3 weeks ago

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 commented 3 weeks ago

4.44.1 has same issue on osx

mikefarah commented 2 weeks ago

Verified - needs fix