Skip to content

yq is confused by the indentation of a comment, considers it belonging to a wrong node. #2054

Open
@OndraZizka

Description

@OndraZizka

yq messes with the comments when just reading and then writing (edit: due to a bug in the underlying go/yaml).

Version of yq: 4.40.05
Operating system: linux, Ubuntu 23.10

Input Yaml

Original:

images:
  ### Some comment
  - name: mounting-app
    ### Other comment
    newName: "foo bar"
    ###  Other comment
    newTag: "foo bar" # Line comment
  ### }

  - name: "Some name"

After any processing by yq:

images:
  ### Some comment
  - name: mounting-app
    ### Other comment
    newName: "foo bar"
    ###  Other comment
    newTag: "foo bar" # Line comment

  - name: "Some name"
  ### }

Notice the difference: The ### } is moved down 2 lines.

My guess is that based on the position, yq determines correctly it is a foot_comment.

But because of indentation, yq determines it as belonging to the node at the same level - the nest array element, starting at - name.

And then mixes it together, and puts it to that node (let's call it .images[1].name) as a foot_comment.

Correct behavior would be, despite it's indentation, assign that as belonging to .images[0].newTag, even if with a misfitting indentation.

Command
More less any command that retains the affected nodes.

Thanks for reviewing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions