Simple built-in types are not converted from string in json
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
WSME |
Fix Released
|
Undecided
|
Stéphane Bisinger |
Bug Description
If I define a function with a built-in type as an argument, the argument is not converted in the correct built-in, but it is passed as is in the REST protocol. So, for instance, a method like this could fail:
class MyService(WSRoot):
@expose(int)
@validate(int)
def add(self, value):
return value + 2
If called with this curl like this:
curl -H "Content-Type: application/json" -X POST -d '{"value": " 3"}' http://
WSME should either return an HTTP 400 status code (because we require an int, but got a string), or try to convert the string to int, only returning a 400 status code if the convertion fails
This is the case for all basic built-in types (bool, int, long, float)
Changed in wsme: | |
assignee: | nobody → Stéphane Bisinger (kjir) |
status: | New → In Progress |
Changed in wsme: | |
milestone: | none → 0.8.0 |
status: | Fix Committed → Fix Released |
Reviewed: https:/ /review. openstack. org/179839 /git.openstack. org/cgit/ stackforge/ wsme/commit/ ?id=9a0d3c1461c 272567653defdfe c1c3680939dbdb
Committed: https:/
Submitter: Jenkins
Branch: master
commit 9a0d3c1461c2725 67653defdfec1c3 680939dbdb
Author: Stéphane Bisinger <email address hidden>
Date: Mon May 4 18:41:32 2015 +0200
Convert built-in types when passed as strings
If on a service exposed with some arguments with a built-in type among
int, long, bool or float a request is made passing a JSON with string
values instead of the intended type, the called function would have
strings as parameters instead of the expected types. This also means
that invalid strings would still be passed without error, leading to
unexpected failures. This patch tries to convert the string to the
intended type before failing with an InvalidInput exception if the
string can't be converted. This is to try and be as nice as possible
with whatever input is thrown at wsme.
Closes-Bug: 1450544 d539074b78ce813 39b9464e1e0
Change-Id: I705c183bb68457