Skip to content

Commit

Permalink
Merge pull request #558 from ImageMarkup/557-api-parse-numbers-as-str…
Browse files Browse the repository at this point in the history
…ings

Fix passing API parameters that can be parsed as numbers
  • Loading branch information
brianhelba committed May 7, 2018
2 parents f9528a7 + ff96797 commit e7fb1e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ def _decodeParams(self, params):
if not isinstance(decodedParams, dict):
raise RestException('JSON content should be an object at the top level.')
else:
# Return parameter unchanged
def passthrough(param):
return param

decodedParams = {}
for field, value in six.viewitems(params):
try:
decodedValue = json.loads(value)
# Decode parameter, parsing numbers as strings
decodedValue = json.loads(value, parse_float=passthrough, parse_int=passthrough)
except ValueError:
# Assume this was just a simple string; invalid JSON should
# be caught later by type checking validation
Expand Down

0 comments on commit e7fb1e8

Please sign in to comment.