Skip to content

Multi-line string marshal output not using block notation consistently #846

@CubicrootXYZ

Description

@CubicrootXYZ

Describe the bug

Marshaling a multi-line string usually results in block notation, but somehow if adding a colon : to the end of the string or starting with an escaped quote character \" the block notation is no longer used.

hello: |-\n  \n  \"name\"\n

vs

hello: \"\\\"name\\\":\"\n

To Reproduce

https://go.dev/play/p/ehf6lfGE7qW

Marshaling map[string]string{"hello": "\"name\":"} does not use block notation, map[string]string{"hello": "\n\"name\""} uses block notation.

Expected behavior

Block notation being used consistently for all multi-line strings.

Version Variables

  • Go version: 1.26.0
  • go-yaml's Version: v1.19.2

Additional context

I stumbled across this when trying to add javascript code examples as multi-line strings to an OpenAPI spec file (yaml format).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions