-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
float number, range validation failure #1274
Comments
Hi there. You haven't provided your code so it's not a sure thing, but I'd bet you've used float division (as it's the default when loading JSON) and expecting non-float behavior. For floats, 5.6 indeed is not divisible by 0.1. If you don't want that, don't use floats, e.g.: ⊙ ~[jsonschema:python] -c '
quote> from pathlib import Path
import decimal
import json
import jsonschema.validators
def load(path):
return json.loads(path.read_text(), parse_float=decimal.Decimal)
fail = load(Path("cve-short-test-fail.json"))
success = load(Path("cve-short-test-success.json"))
schema = load(Path("number_float_schema.json"))
Validator = jsonschema.validators.validator_for(schema)
validator = Validator(schema)
print(validator.is_valid(fail))
print(validator.is_valid(success))
'
True
True (I thought I'd added this to the FAQ, but it's certainly covered in quite a few previous issues. I'll add it at some point.) |
Thank you for the fast answer @Julian
I also tried the same with I can see how this could be solved. |
I'm not as familiar with check-jsonschema as one might expect, but I'd either look for an option there to configure how it deserializes JSON or else in the event it doesn't yet have one, open an issue. |
Thanks, I tried your proposal on the original codebase (cvelib), and it fixes the issue. Many thanks ! |
It seems that jsonschema fails to properly validate number type in a range.
cve-short-test-fail.json
cve-short-test-success.json
number_float_schema.json
When using jsonschema to validate float number in a range, the validation fails.
Attached
the failure tested on python 3.12.4 , jsonschema 4.22 (screenshots attached )


Schema was tested successfully, no validation error in
The text was updated successfully, but these errors were encountered: