kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.62k stars 84 forks source link

yq complains of duplicate anchors #66

Open lousyd opened 5 years ago

lousyd commented 5 years ago

I have a file like this:

$ cat test.yml 
app: testyaml
because: &because
  - testing
  - iswhy
reason: &because
why: *because

...and get this error when processing it with yq:

$ yq '.' test.yml 
yq: Error running jq: ComposerError: found duplicate anchor 'because'; first occurrence
  in "test.yml", line 2, column 10
second occurrence
  in "test.yml", line 5, column 9.

According to the YAML specs, duplicate anchors are valid:

3.2.2.2. Anchors and Aliases

[...] When composing a representation graph from serialized events, an alias node refers to the most recent node in the serialization having the specified anchor. Therefore, anchors need not be unique within a serialization. [...]

7.1. Alias Nodes

[...] The alias refers to the most recent preceding node having the same anchor. [...]

kislyuk commented 5 years ago

yq depends on PyYAML for YAML deserialization. This bug is therefore blocked by https://github.com/yaml/pyyaml/issues/100 in PyYAML. Please file a comment or new issue in that reposotory.

Is there a specific use case that you have in mind?

lousyd commented 5 years ago

Thank you for the reference. I don't have a representative use case, I don't think. I just came across the problem while trying to process gitlab ci yaml files. Some of the files have duplicate anchors. I modified a local copy of those files in order to workaround the problem for the time being.