Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Preserve double quotes around "yes" and "no" strings #319

Open
RandomGHUser opened this issue Sep 1, 2022 · 1 comment · May be fixed by #412
Open

Preserve double quotes around "yes" and "no" strings #319

RandomGHUser opened this issue Sep 1, 2022 · 1 comment · May be fixed by #412

Comments

@RandomGHUser
Copy link

RandomGHUser commented Sep 1, 2022

I am having an issue with preserving string values of "yes" and "no" after converting from str -> yaml value -> (string/str). "yes" is not the same as yes (YAML version 1.1 interprets the latter as bool). Is there a setting or flag I can set to preserve the double quotes around strings yes and no, so they do not get interpreted as bools?

let _str = r#"
QuoteYes: "yes"
QuoteNo: "no"
RegYes: yes
RegNo: no
"#;
let to_yaml = serde_yaml::from_str::<serde_yaml::Value>(_str).unwrap();
let to_str = serde_yaml::to_string(&to_yaml).unwrap();
std::fs::write("./test.yaml", &to_str);

expected output file:

QuoteYes: "yes"
QuoteNo: "no"
RegYes: yes
RegNo: no

actual output file:

QuoteYes: yes
QuoteNo: no
RegYes: yes
RegNo: no
@L1ghtman2k
Copy link

Same for on/off.

Ex: nginx annotation in k8s manifest file:
yaml value -> (string/str) in serde 0.8.26 produces:
nginx.ingress.kubernetes.io/proxy-buffering: "on"

however, serde 0.9.13 produces:
nginx.ingress.kubernetes.io/proxy-buffering: on

which in our case ends up throwing an error, when we try to run kubectl apply:

error: unable to decode "/tmp/.tmpfwYrJw/base/ingress.yaml": resource.metadataOnlyObject.ObjectMeta: v1.ObjectMeta.Annotations: ReadString: expects " or n, but found t, error found in #10 byte of ...|ffering":true,"nginx|..., bigger context ...|K","nginx.ingress.kubernetes.io/proxy-buffering":true,"nginx.ingress.kubernetes.io/ssl-redirect":"tr|...

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

Successfully merging a pull request may close this issue.

2 participants