Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra newline is added after empty values #474

Open
laurynasr opened this issue May 18, 2023 · 2 comments
Open

Extra newline is added after empty values #474

laurynasr opened this issue May 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@laurynasr
Copy link

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 laurynasr added the bug Something isn't working label May 18, 2023
@eemeli
Copy link
Owner

eemeli commented May 19, 2023

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.

@rafgugi
Copy link

rafgugi commented Jul 12, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants