diff options
-rw-r--r-- | extmod/modujson.c | 3 | ||||
-rw-r--r-- | tests/extmod/ujson_loads.py | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/extmod/modujson.c b/extmod/modujson.c index a7b889676a..d1d103237e 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -239,7 +239,8 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { // unexpected chars goto fail; } - if (stack.len != 0) { + if (stack_top == MP_OBJ_NULL || stack.len != 0) { + // not exactly 1 object goto fail; } vstr_clear(&vstr); diff --git a/tests/extmod/ujson_loads.py b/tests/extmod/ujson_loads.py index 05bd62a9b2..75e61dacd9 100644 --- a/tests/extmod/ujson_loads.py +++ b/tests/extmod/ujson_loads.py @@ -33,3 +33,9 @@ my_print(json.loads('{"a":[], "b":[1], "c":{"3":4}}')) # whitespace handling my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}')) + +# loading nothing should raise exception +try: + json.loads('') +except ValueError: + print('ValueError') |