extmod: Make ujson.loads raise exception if given empty string.

Addresses issue #1097.
stackless
Damien George 2015-02-02 21:52:19 +00:00
parent e8b877be60
commit 5f64dc55d8
2 changed files with 8 additions and 1 deletions

View File

@ -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);

View File

@ -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')