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:
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
const yaml = 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 76
base64lines = 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
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.0