Skip to content

Comments affecting Unique operator behaviour #2491

@CobusTheunissenSE

Description

@CobusTheunissenSE

Describe the bug
The Unique operator exhibits unexpected behaviour when comments are present in between a list of yaml objects.

Version of yq: 4.47.2
Operating system: mac/linux
Installed via: binary release/homebrew

Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
data1.yml:

- id: 1001
# Comment
- id: 1001

Command
The command you ran:

yq 'unique' data1.yml

Actual behavior

- id: 1001
# Comment
- id: 1001

Expected behavior

- id: 1001

Additional context
In the following scenarios, the operator behaves as expected:

  • Comments are just at the top or bottom.
  • The duplicate items in the list are not yaml objects.
  • If there is an object between the duplicate objects without another comment:

data1.yml:

- id: 1001
# Comment
- id: 1002
- id: 1001

Output:

- id: 1001
# Comment
- id: 1002

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions