yaml icon indicating copy to clipboard operation
yaml copied to clipboard

Extra newline is added after empty values

Open laurynasr opened this issue 2 years ago • 2 comments

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

laurynasr avatar May 18 '23 14:05 laurynasr

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.

eemeli avatar May 19 '23 11:05 eemeli

although this is very tricky, can we fix by removing triple newlines? 😁

rafgugi avatar Jul 12 '23 07:07 rafgugi