Skip to content

foot_comment only in the duplicated node -> not retrievable nor updatable #2483

@NickVeld

Description

@NickVeld

Describe the bug
There are some issues with foot_comment ( #1726 #2054 ). But this issue might have some idea about a workaround to the problem of the underlying yaml parser.

The problem itself is that the foot_comment is not retrievable and cannot be updated.

Version of yq: 4.44.6
Operating system: linux
Installed via: binary release

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

a:
  - b: "1" # xyz
    # abc

Command
The command you ran:

yq '.a[0].b | foot_comment' example.yml
echo '---'
yq '.a[0].b foot_comment = "def"' example.yml

Actual behavior

---
a:
  - b: "1" # xyz
    # def

    # abc

Expected behavior

abc
---
a:
  - b: "1" # xyz
    # def

Additional context

First of all, line_comment works good in this case. (xyz is returned)

yq '.a[0].b | line_comment' example.yml

I found the result of this command intresting. The foot_comment can find the target comment after all. Even with the right path:

yq '... | select(foot_comment == "abc") | ( path | join(".") )' example.yml

produces

a.0.b

What is more intresting

yq '... | foot_comment' example.yml

produces





abc

and

yq '... | foot_comment | ( path | join(".") )' example.yml

produces

a
a
a.0
a.0.b
a.0.b

So there are two pair of nodes (a + a.0.b) with the same path. And only the last a.0.b has the target foot_comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions