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 are being de-quoted depending on output format #2011

Closed
ryan-ph opened this issue Apr 12, 2024 · 1 comment
Closed

String values are being de-quoted depending on output format #2011

ryan-ph opened this issue Apr 12, 2024 · 1 comment
Labels

Comments

@ryan-ph
Copy link

ryan-ph commented Apr 12, 2024

Describe the bug

Somewhat related to #914

When specifying --output, strings are de-quoted in some formats and remain quoted in others. This inconsistency between output formats seems like a bug.

Note that any how to questions should be posted in the discussion board and not raised as an issue.

Version of yq: v4.43.1
Operating system: Mac
Installed via: Homebrew

Input Yaml

quoted.yml:

key: "Off"

unquoted.yml:

key: Off

Command
The command you ran:

$ yq -o=$FORMAT quoted.yaml

Actual behavior

$ yq -o=yaml quoted.yaml
key: "Off"

$ yq -o=props quoted.yaml
key = Off

Expected behavior

$ yq -o=yaml quoted.yaml
key: "Off"

$ yq -o=props quoted.yaml
key = "Off"

Additional context

Specifically, this causes issues when trying to diff as suggested in tips and tricks for files using YAML 1.1 (i.e. k8s manifests).

The guide suggests using diff to compare semantic differences, but because of the inconsistent quoting, this can lead to issues:

$ diff <(yq 'sort_keys(..)' -o=props quoted.yaml) <(yq 'sort_keys(..)' -o=props unquoted.yaml)

$ diff <(yq 'sort_keys(..)' -o=yaml quoted.yaml) <(yq 'sort_keys(..)' -o=yaml unquoted.yaml)
1c1
< key: "Off"
---
> key: Off
@ryan-ph
Copy link
Author

ryan-ph commented Apr 12, 2024

Ah I see this is actually handled by the --unwrap-scalar flag.

type PropertiesPreferences struct {
UnwrapScalar bool
KeyValueSeparator string
UseArrayBrackets bool
}

@ryan-ph ryan-ph closed this as completed Apr 12, 2024
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

1 participant