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

Empty Multiline Array Is Having an Empty Line and Whitespace Added Before It #590

Closed
pjkaufman opened this issue Nov 22, 2024 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@pjkaufman
Copy link

Describe the bug
Thanks for creating this YAML parser. I have been working on using it in one of my projects and I have hit a weird scenario. It seems that in some cases, empty multi-line arrays are having their empty entry moved down a line and having its indentation space added on the line it was on. I am not sure if this YAML is considered correct under the YAML spec in use, so please let me know if the YAML is incorrect/out of spec.

To Reproduce

parseDocument then toString the following YAML:

FFF:
  - 

It seems to result in:

---
FFF:
  
  - 
---

This seems wrong to me, but maybe that is what the spec dictates should happen.

Expected behaviour

I expect the output to be as close to, if not the same as, the input as is possible:

FFF:
  - 

Versions (please complete the following information):

  • Environment: Node v18.0.0
  • yaml: 2.6.0

Additional context
I am not 100% sure on how nesting levels would affect this or if it would be fine to try to investigate the root cause of the issue. But I would be happy to take a stab at it if you are fine with that.

@eemeli
Copy link
Owner

eemeli commented Nov 23, 2024

Was able to replicate this; this is happening because a newline after a - sequence indicator is setting spaceBefore on the node, and when stringifying that's getting serialised before the - indicator.

Decided to fix this by ignoring newlines after the - for spaceBefore consideration.

@pjkaufman
Copy link
Author

Thanks for the quick turn around on this as well as creating and maintaining this library!

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

2 participants