-
Notifications
You must be signed in to change notification settings - Fork 340
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
Fix validation of payloads containing floats #45
Conversation
DeepCode Report (#5fc60d)DeepCode analyzed this pull request. |
ocpp/messages.py
Outdated
@@ -32,7 +33,7 @@ def unpack(msg): | |||
Unpacks a message into either a Call, CallError or CallResult. | |||
""" | |||
try: | |||
msg = json.loads(msg) | |||
msg = json.loads(msg, parse_float=decimal.Decimal) |
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.
Is it ok to always parse floats here but only schemas in a few instances?
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.
Good catch, I need to verify that.
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 started working on this a bit yesterday, and I got stuck on that part of porting the code over. If it's an issue I have an idea.
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've removed the argument parse_float=decimal.Decimal
. It is not needed in this place.
If a message requires special validation regarding the floats the message is reparsed again using parse_float=decimal.Decimal
. See line 143 of this file.
9a5a31f
to
7d28d63
Compare
The validation of payloads using jsonschemas could fail when the payload contained a float. This problem is described in this issue: python-jsonschema/jsonschema#247 This commit implements a work around for this issue by changing the float parser for certain payloads from `float()` to `decimal.Decimal()`. Fixes: #43
7d28d63
to
c2f3718
Compare
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.
LGTM
The validation of payloads using jsonschemas could fail when the payload
contained a float. This problem is described in this issue:
python-jsonschema/jsonschema#247
This commit implements a work around for this issue by changing the
float parser for certain payloads from
float()
todecimal.Decimal()
.Fixes: #43