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

String values that are legal YAML 1.1 boolean values are de-quoted by --prettyprint #914

Closed
dwd opened this issue Aug 11, 2021 · 4 comments
Labels
Milestone

Comments

@dwd
Copy link

dwd commented Aug 11, 2021

Describe the bug

See: http://yaml.org/type/bool.html

String values that are treated as implicitly boolean by some processors are treated as strings by yq, and pretty-printing therefore removes the quotes, causing the tag to implicitly change.

This is surprising, because it looks to me as though the underlying go-yaml library has the existing support for this.

Version of yq: 4.11.2
Operating system: Linux
Installed via: go get github.com/mikefarah/yq/v4

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

a_string_value: "yes"

Command
The command you ran:

yq -Pe e '.' input.yml

Actual behavior

a_string_value: yes

Expected behavior

a_string_value: "yes"

Additional context

Similarly, b: yes run through yq -Pe e 'b | tag' results in !!str, whereas it should arguably be !!bool - this matters rather less than the output above.

It looks like this relates to YAML 1.1, rather than YAML 1.2, so this probably isn't a "bug" in the "you did something wrong" sense, but it's problematic because existing processors (including parts of Docker) appear to treat an unquoted "yes" as implicitly a !!bool.

@mikefarah
Copy link
Owner

yeah this is definitely a YAML 1.1 vs 1.2 thing - the yaml parser yq uses is for 1.2 - so 'yes' is never a boolean in its eyes.

The prettyPrint flag could be updated to leave the existing styling of any nodes with yes/no/on/off values so it doesn't break 1.1 - would that work?

@thatsk
Copy link

thatsk commented Aug 18, 2021

same with me also.

thatsk@example: ~$ cat kunal.yaml 
test: "on"
key: "off"
thatsk@example: ~$ yq4 -Pe e '.' kunal.yaml 
test: on
key: off

@thatsk
Copy link

thatsk commented Aug 18, 2021

i need the quotes but pretty print is removing it

@mikefarah mikefarah added this to the 4.11.3 milestone Aug 19, 2021
@mikefarah
Copy link
Owner

Fixed in 4.12.0

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

3 participants