validator: check invalid floats NaN/Inf#249
Merged
santhosh-tekuri merged 1 commit intosanthosh-tekuri:boonfrom Feb 18, 2026
Merged
validator: check invalid floats NaN/Inf#249santhosh-tekuri merged 1 commit intosanthosh-tekuri:boonfrom
santhosh-tekuri merged 1 commit intosanthosh-tekuri:boonfrom
Conversation
c65c01f to
900a81c
Compare
nan_inf_test.go
Outdated
| "github.com/santhosh-tekuri/jsonschema/v6" | ||
| ) | ||
|
|
||
| func TestNaNInfPanic(t *testing.T) { |
Owner
There was a problem hiding this comment.
change function name to TestInvalidFloats
nan_inf_test.go
Outdated
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := c.AddResource("test.json", doc); err != nil { |
Owner
There was a problem hiding this comment.
use schema.json instead of test.json
| @@ -0,0 +1,32 @@ | |||
| package jsonschema_test | |||
Owner
There was a problem hiding this comment.
change filename to validator_test.go
change commit msg: validator: check invalid floats NaN/Inf
900a81c to
84d5337
Compare
84d5337 to
795b912
Compare
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 #248.
typeOf()now returnsinvalidTypefor NaN/Inffloat64andfloat32values, so they hit the existingInvalidJsonValueerror path at validator.go:92-94 instead of reachingnumValidate()wherebig.Rat.SetStringreturns nil.What changed
schema.go: split thefloat64andfloat32cases out of the numeric type switch intypeOf(), addingmath.IsNaN/math.IsInfguards that returninvalidTypenan_inf_test.go: test that all three values (NaN, +Inf, -Inf) produce a validation error instead of a panicAlternative considered
A guard at the top of
numValidate()would also work, but catching it intypeOf()prevents these values from reaching any validation logic at all.