-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Marshal YAML 1.1 bool-like to strings #583
Conversation
Fixes #582 |
encode.go
Outdated
@@ -320,6 +320,15 @@ func (e *encoder) stringv(tag string, in reflect.Value) { | |||
// there's no need to quote it. | |||
rtag, _ := resolve("", s) | |||
canUsePlain = rtag == strTag && !isBase60Float(s) | |||
|
|||
// Maintain some backward compatibility with YAML 1.2 | |||
if rtag == strTag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be slightly nicer if we had it inside something like isOldBool and put the test next to the isBase60Float above, as that method is the exactly equivalent except for base 60 floats (!!!, and you thought the on/off situation was bad).
Checking for isBase60Float usage should find us the exact places we need to care about. Well, either that or we have two bugs instead of one.. ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, have moved the check out and added the test to the above line. it does read more clearly.
We adhere to the YAML 1.3 for input, but only parsing "On", "Off", and friends, as strings rather than bools. When outputting however we will ensure that we quote these cases. Failure to do so forces makes the output ambiguous if it then to be parsed by a YAML 1.2 parser.
Thanks, glad to merge this. Have you signed the contributor agreement before? It's trivial to sign online, and it's a non-draconian licensing with you retaining ownership: |
I think I just signed the form, I put you down as "Canonical Project Manager or contact" |
Thanks! |
For the record, please note that those are YAML 1.1 strings, vs. the new 1.2 style that is more strictly implemented in go-yaml v3 (not 1.2 and 1.3). Thanks again for your help. |
Right, thanks. I had it my head the "fix" to the spec was in 1.3, I think I saw that on the issue that pointed out they've been removed. I think I fixed the comments and the PR title, but not the commit message. |
I'm not 100% sure if this is the right place to do this, it works, and
is somewhat in the spirit of decode.go. I've put an explanation of the
reasoning in the commit, not sure if you'd rather have something in the README.