Skip to content

Strings with tabs and newlines can't be serialized as block quotes #682

Open
@beckjake

Description

@beckjake

The dumper code (in chooseScalarStyle) checks in a couple places to see if any characters in the string to be written are non-printable, and if so only allows double-quoted output. This is mostly fine, except tabs are explicitly excluded from the "printable" set (there's a comment implying it's intentional). That means that any block quote with tabs is unconditionally rendered as a single-line double-quoted string.

For example, loading+dumping this:

value: |-
  a
  	b

results in this:

value: "a\n\tb"

obviously this example is trivial and no big deal, but with a very large string that has embedded tabs (for example, an example program embedded in a value of a yaml block), you can imagine it gets pretty ugly.

For my needs it'd be enough to change the isPrintable checks in chooseScalarStyle to also accept tabs (0x09), but I think there's a pretty reasonable case to be made for carriage returns and non-breaking spaces too. It turns out I also need carriage returns and newlines, so I've patched that as well in my PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions