-
Notifications
You must be signed in to change notification settings - Fork 36
Fix decoding numbers with plus sign into uint64 #136
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR fixes an issue where YAML decoding of unsigned 64-bit integers fails when the number includes a plus sign prefix (e.g., +0xFFFFFFFFFFFFFFFF). The fix removes the plus sign before parsing to make it compatible with Go's strconv.ParseUint function.
- Modified the parsing logic to strip plus signs from numeric strings before converting to uint64
- Added comprehensive test cases for both decimal and hexadecimal numbers with plus signs
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| resolve.go | Updated uint64 parsing to handle plus sign prefix by trimming it before calling strconv.ParseUint |
| decode_test.go | Added test cases for decimal and hexadecimal uint64 values with plus sign prefixes |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
24249b3 to
c17655a
Compare
|
AFAIK '+' isn't allowed in integer representation. |
|
Why |
|
Anyway, the parser already parses the plus sign, and this PR fixes a corner case, so this is not the right place to discuss on dropping the plus sign support. Currently |
I had the same consideration before validating the PR. If the rest supports it, I see no problem with it.
I checked yesterday before validating the PR As I found nothing clear I tried with other libraries that parse YAML (in other languages), all of them where allowing the + So I validated it.
Indeed. |
|
When encoding a value in the canonical form, the |
|
This topic falls under the concept of YAML Schemas https://yaml.org/spec/1.2.2/#chapter-10-recommended-schemas YAML was designed so that a loader can be configured to use any yaml-schema rules it wants to. The spec then defines 3 basic yaml-schemas, failsafe, json (which doesn't actually follw all the json rules as you'd expect) and core. go-yaml can actually choose whatever makes the most sense for Go. What I really want in the world is an easy standard way for any domain (like say kubernetes) to define their own yaml-schemas and have go-yaml accept a yaml-schema as a loader config option. Back to the problem at hand. The Core yaml-schema https://yaml.org/spec/1.2.2/#1032-tag-resolution clearly shows that But we can also provide other more sensible "baked-in" yaml-schema options, and eventually user defined ones. |
IN YAML "parser" means something very specific. It has no logic around a A YAML "loader" is the combination of these transforms. Unfortunately, the go-yaml author chose to break from YAML terminology and use the term unmarshal and decode, which are foreign to the YAML vocabulary. I would like us all to learn and use the correct terminology for this project. |
Well, Unmarshall is the term used for JSON in Go standard library. Using it for a library handling YAML in Go was somehow normal to me. But I get your point. |
|
@itchyny I didn't forget your PR. I worked on it to try to figure what is expected in YAML, what is the existing go-yaml code doing. I also explored the notion of tag and canonical form, as they were unclear to me. I added 50+ unit tests, and I found bugs with the code that was already there with the v3. I'll try to sort things and go back to you when I can. |
c17655a to
0233287
Compare
ccoVeille
left a comment
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.
I looked again at the PR.
The PR is fine. It brings support for something that is valid depending on the YAML specs 1.1 or 1.2
So, I would say the code is fine.
Later we may fix what is not valid depending on the spec and whether the value is used in the canonical form.
But for, now I think we are good.
Thanks @itchyny
Of course, I might be wrong and I would be happy to read feedback from others.
Currently, decoding
+0xFFFFFFFFFFFFFFFFintouint64fails becausestrconv.ParseUintdoes not accept the+sign.