Skip to content

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

Closed

Description

@pjkaufman

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.

Activity

  1. added
    bug
    on Nov 22, 2024
  2. eemeli commented on Nov 23, 2024

    @eemeli
    Owner

    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.

  3. added a commit that references this issue on Nov 23, 2024
    38affe5
  4. pjkaufman commented on Nov 23, 2024

    @pjkaufman
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions