Repository navigation
fix: read float-tagged int64 schema keywords instead of storing 0 - #666
Open
TastyHeadphones wants to merge 1 commit into
Open
TastyHeadphones wants to merge 1 commit into
TastyHeadphones wants to merge 1 commit into
Conversation
maxLength, minLength, maxItems, minItems, maxProperties and minProperties accept int and float nodes, but the value was parsed with strconv.ParseInt and the error ignored, so 2.0 or 1.7976931348623157E+308 became 0. Whole-number floats are now converted, floats at or beyond the int64 range (and .inf / -.inf) clamp to math.MaxInt64 / math.MinInt64 like ParseInt does for out-of-range integers, and fractions or NaN leave the field unset. Fixes pb33f#665
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #666 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 309 309
Lines 39178 39198 +20
=========================================
+ Hits 39178 39198 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #665
setFieldNodeReferenceInt64Typeaccepts int and float nodes, but parsed the value withstrconv.ParseInt(..., 10, 64)and ignored the error. A float such asmaxLength: 2.0ormaxItems: 1.7976931348623157E+308therefore became0, so a validator built on the model rejected every non-empty string or array.Changes in
datamodel/low/model_builder.go:parseInt64Nodehelper, used by theNodeReference[int64]and[]NodeReference[int64]casesParseInt's clamping of out-of-range integers tomath.MaxInt64/math.MinInt642.0→ 2,1e3→ 1000).inf/-.inf, clamps tomath.MaxInt64/math.MinInt64, the same asParseIntdoes for an out-of-range integer2.5) or.nanleaves the field unset, so the high-level pointer staysnilinstead of pointing at0. JSON Schema requires these keywords to be non-negative integers, so such a schema is invalid anyway. If you'd prefer a different behaviour for fractions (e.g. rounding), it's a one-line change.0when they don't parseTests:
TestBuildModel_Int64FromFloatAndRange/TestBuildModel_Int64SliceFromFloatindatamodel/low/model_builder_test.gocover the parse cases throughBuildModelissue665_test.goreproduces the report throughNewDocument+BuildV3Model(2.0→ 2,1.7976931348623157E+308→math.MaxInt64,5→ 5,2.5→ nil)Both new tests fail on
mainand pass with this change.go vetis clean, andgo test ./...passes exceptFuzzAppendJSONString/seed#5in./json, which also fails onmainwith my local Go 1.27.2 (it's about\ufffdescaping and unrelated to this change).AI disclosure: Grok (xAI) wrote the first draft of this change and its tests. I reviewed it, simplified the helper's
.infhandling, and ran the tests myself. I'm responsible for the change.