You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
beckjake
changed the title
Strings with tabs can't be serialized as block quotes
Strings with tabs and newlines can't be serialized as block quotes
Sep 15, 2022
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:
results in this:
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 inchooseScalarStyle
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.The text was updated successfully, but these errors were encountered: