diff options
-rw-r--r-- | wsme/rest/json.py | 2 | ||||
-rw-r--r-- | wsme/tests/test_restjson.py | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/wsme/rest/json.py b/wsme/rest/json.py index 594916c..48bd082 100644 --- a/wsme/rest/json.py +++ b/wsme/rest/json.py @@ -274,6 +274,8 @@ def parse(s, datatypes, bodyarg, encoding='utf8'): else: kw = {} extra_args = [] + if not isinstance(jdata, dict): + raise wsme.exc.ClientSideError("Request must be a JSON dict") for key in jdata: if key not in datatypes: extra_args.append(key) diff --git a/wsme/tests/test_restjson.py b/wsme/tests/test_restjson.py index 3368703..d7c8110 100644 --- a/wsme/tests/test_restjson.py +++ b/wsme/tests/test_restjson.py @@ -339,6 +339,14 @@ class TestRestJson(wsme.tests.protocol.RestOnlyProtocolTestCase): j = parse('{"a": "2011-01-01"}', {'a': datetime.date}, False) assert isinstance(j['a'], datetime.date) + def test_invalid_root_dict_fromjson(self): + try: + parse('["invalid"]', {'a': ArrayType(str)}, False) + assert False + except Exception as e: + assert isinstance(e, ClientSideError) + assert e.msg == "Request must be a JSON dict" + def test_invalid_list_fromjson(self): jlist = "invalid" try: |