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
I had some Base64 data which I formatted onto lines of length 76 separated by newlines. I embedded it into some data, stringified with YAML and the results looked like:
foo:
bar:
baz:
base64: >- dGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0 ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRl c3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIA==
It would make more sense to use the | instead of > and then it wouldn't need to put a blank line between each line of data. I can see that it hasn't done that because it sees the lines are long, so it wants to wrap them at spaces, but there are no spaces to wrap.
I was able to fix it by shortening my base64 line length, but 76 is the standard for base64.
To Reproduce
constyaml=require("yaml");// Get some base64 data (any long string with no whitespace would do)base64data=btoa("testing ".repeat(20));// Split it over lines of length 76base64lines=base64data.replace(/(.{76})/g,"$1\n"),data={foo: {bar: {baz: {base64: base64lines},},},};console.log(yaml.stringify(data));
Expected behaviour
foo:
bar:
baz:
base64: |- dGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0 ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRl c3RpbmcgdGVzdGluZyB0ZXN0aW5nIHRlc3RpbmcgdGVzdGluZyB0ZXN0aW5nIA==
Versions (please complete the following information):
Environment: Node v21.7.1
yaml: 2.6.0
The text was updated successfully, but these errors were encountered:
There is a real issue here, but I'm not sure if it should be solved.
By default, we assume that the content in YAML is human-readable, and that therefore it's reasonable to assume that it has some whitespace. Further, if we're dealing with multiline content with lines that need folding, we assume that the > style is approriate. In this case, these assumptions produce suboptimal results, as the lines don't actually include any whitespace and will overflow the soft wrap boundary that's at 80 characters by default.
It's possible to work around this by at least three different ways:
Extend the line width with { lineWidth: 100 } so that the indented contents don't overflow.
Enforce the block quote style with { blockQuote: 'literal' }.
Represent the binary data as a Buffer or UInt8Array, and use { customTags: ['binary'] }. This will tag the value as !!binary, which is supported by parse() by default:
Now, despite all that, it would still be nice to detect the overflow with > and default to | block quote style in the original case. I may experiment with this a bit.
Describe the bug
I had some Base64 data which I formatted onto lines of length 76 separated by newlines. I embedded it into some data, stringified with YAML and the results looked like:
It would make more sense to use the
|
instead of>
and then it wouldn't need to put a blank line between each line of data. I can see that it hasn't done that because it sees the lines are long, so it wants to wrap them at spaces, but there are no spaces to wrap.I was able to fix it by shortening my base64 line length, but 76 is the standard for base64.
To Reproduce
Expected behaviour
Versions (please complete the following information):
yaml
: 2.6.0The text was updated successfully, but these errors were encountered: