-
Notifications
You must be signed in to change notification settings - Fork 134
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
Force quotes #382
Comments
Hey @lorenzobenvenuti. Thank you for the question. It's a design goal of The output from The spot where strings are encoded checks to see if the value would reliable resolve to a YAML tag and only includes quotes when it is ambiguous: The closest value that I can think of that would encode to a quote string is to prefix or suffix the value with whitespace: a: #@ "foo"
b: #@ "123"
c: #@ "123.5"
d: #@ "#foo"
e: #@ "74e3 " which encodes to: a: foo
b: "123"
c: "123.5"
d: '#foo'
e: '74e3 ' https://carvel.dev/ytt/#gist:https://gist.github.com/pivotaljohn/44e4c0f6dae722e10f1f3be769087bf3 Could that work in your situation? |
Hi @pivotaljohn, thank you very much for your reply. I'll try your workaround, my initial idea was to add a trailing Speaking of the YAML spec, I gave a quick look and I see two different regular expressions for floating point numbers:
(I copied the regexps from the YAML spec, I guess spaces are used just to increase readability) The one used in ytt to resolve tags is missing a Thanks, lorenzo |
@cppforlife what's the word on patching the YAML parser? |
we use |
Hi, I didn't notice that ytt was "embedding" some code from var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`) The relevant part (at least for my issue) is That part was updated ~2 years ago in this commit Thanks |
(apologies for the delay, @lorenzobenvenuti) Well this makes it all very interesting. 😄
Okay, and so we're tacking to a conversation about upgrading to the id'ed version of the Go YAML v2 package that contains this modified regular expression. To make progress on this idea, we'd need to:
and from there we can have an informed conversation about the potential risks of making the upgrade. FWIW: as of go-yaml/yaml@496545a (at the time of writing, the |
For the immediate term, @lorenzobenvenuti, is one of the currently identified workarounds "sufficient" for the case? |
Yes, thanks! |
FWIW, we have done the legwork; @lorenzobenvenuti, the commit you pointed us to was cherry-pick-able as is and we've got a PR (#483) to merge it in. |
Delivered in release v0.37.0. |
YAML specification supports type forcing with tags: https://yaml.org/spec/1.2.2/#24-tags
Result should be string like |
Hi,
is there any way to force quotes for string values? I understand ytt will enclose a value in quotes when the value can be parsed as a number, or it's prefixed with a "special" character (
#
,@
, ...), for example:Gives
I have a scenario where a value can be in the form
\d+e\d+
(i.e.74e3
):which gives
The yaml we're producing is processed by another tool that inteprets the value above as a number in scientific notation, and the value is changed (
74e3
is translated into74000.0
).Adding quotes forces the downstream system to parse the value as a string, but I didn't find a way to tell ytt to explicitly add quotes (or add some raw content to the output). Is this feature supported?
Thanks,
lorenzo
The text was updated successfully, but these errors were encountered: