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.6k stars 83 forks source link

yq rewrites key 'on' to 'true' #148

Closed kftsehk closed 2 years ago

kftsehk commented 2 years ago

happens in github action yaml

test.yaml:

on: push

test case:

yq --version
# yq 2.14.0

jq --version
# jq-1.6

yq -i -S -Y test.yaml && cat test.yaml
# 'true': push

the output is not equivalent to on: push, in my opinion, on to true transform should only be applied to values, not keys

Current workaround is

'on': push
kislyuk commented 2 years ago

I appreciate the frustration. Unfortunately, this is a flaw in the underlying YAML language specification, not something that yq has any control over. We rely on PyYAML to interpret the language for us.

Luckily, YAML 1.2 eliminates this unintuitive behavior and treats on like any other string literal. Unfortunately, PyYAML does not support YAML 1.2 and progress in implementing it has been very slow (I opened https://github.com/yaml/pyyaml/issues/116 almost 5 years ago and while a PR appeared about a year ago, it has not seen progress since).

PyYAML's most suitable competitor in this space, ruamel.yaml, does support YAML 1.2 but has its own issues and we currently have no plans to switch to it.

kftsehk commented 2 years ago

Thanks for explaining, the good side is there is a workaround.

kislyuk commented 2 years ago

v3.0.1 enables YAML 1.2 support, so this issue should now be fixed.