Skip to content

Multi-line strings erroneously written as single line in the presence of some UTF8 chars #2797

Description

@spockz

Describe the bug
When updating a yaml to add/update a field with a multi-line string the field is emitted as a single line string with encoded newlines instead of a multiline in the presence of some UTF8 characters.

I first thought my issue was due to trailing spaces like in #2030.

Version of yq: 4.53.3 (yq (https://github.com/mikefarah/yq/) version v4.53.3
Operating system: linux (Linux cachyos-x8664 7.1.5-1)
Installed via: pacman

See repository spockz/yq-multiline-reproducer.

Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
some.yml:

foo: bar

broken.md

Multiline file containing

🚧

A "weird" utf8 char?

works.md

Multiline file containing

✅

A "less weird" utf8 char?

Command
The command you ran:

yq eval '.longDescription |= (load_str("broken.md"))' some.yaml

Actual behaviour

foo: bar
longDescription: "Multiline file containing\n\n\\n\nA \"weird\" utf8 char?\n"

Expected behaviour

foo: bar
longDescription: |
  Multiline file containing

  🚧

  A "weird" utf8 char?

Interestingly, this does work for some characters:

yq eval '.longDescription |= (load_str("works.md"))' some.yaml
foo: bar
longDescription: |
  Multiline file containing



  A "less weird" utf8 char?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions