yaml
yaml copied to clipboard
Extra newline is added after empty values
Describe the bug The library adds an additional newline after an empty value and a newline
To Reproduce
import { parseDocument } from 'yaml';
import { createPatch } from 'diff';
const yaml = `
map:
item:
anothermap:
anotheritem:
`;
const document = parseDocument(yaml);
const result = document.toString();
const patch = createPatch('output', yaml, result);
console.log(patch);
Output:
Index: output
===================================================================
--- output
+++ output
@@ -1,7 +1,8 @@
-
map:
item:
+
anothermap:
anotheritem:
+
Expected behaviour Expected output:
Index: output
===================================================================
--- output
+++ output
Versions (please complete the following information):
- Environment: Node v16.16.0
yaml: 2.2.2
Yup, that's a bug. The empty value ends up with a spaceBefore: true, even though that should probably end up on the subsequent anothermap key.
PR welcome, not sure when I might get to this myself.
although this is very tricky, can we fix by removing triple newlines? 😁