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

Processing of comments in XML is buggy #1446

Closed
Kopfbremse opened this issue Nov 24, 2022 · 3 comments
Closed

Processing of comments in XML is buggy #1446

Kopfbremse opened this issue Nov 24, 2022 · 3 comments
Labels

Comments

@Kopfbremse
Copy link

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

Bug description
Comments in XML are parsed with type == "!!null".
Order of comments and nodes are not stable.

Input

<root>
  <!-- comment 1 -->
</root>

Undefined type for comments

yq --input-format xml '.. | type' input.xml

Output

!!map
!!null

The order of comment and root node are swapped

yq --input-format xml '.' input.xml

Output

# comment 1
root:

It is not possible to select the comments for further processing

yq --input-format xml '.. | select(type == "!!null")' input.xml

The command produces no output.


The comment is selected together with the map

yq --input-format xml '.. | select(type == "!!map")' input.xml

Output

# comment 1
root:
@mikefarah
Copy link
Owner

Yeah it's been real hard to put the comments in the right place, I'd be surprised if there weren't more issues.
Will fix in next release

@mikefarah
Copy link
Owner

For the record, comments placed above the map key like that are on the map key node, not the value. You'll need to use triple dots ... or the key operator to select them

@mikefarah
Copy link
Owner

Fixed in 4.30.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants