Skip to content

Commit 5f64dc5

Browse files
committed
extmod: Make ujson.loads raise exception if given empty string.
Addresses issue adafruit#1097.
1 parent e8b877b commit 5f64dc5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

extmod/modujson.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
239239
// unexpected chars
240240
goto fail;
241241
}
242-
if (stack.len != 0) {
242+
if (stack_top == MP_OBJ_NULL || stack.len != 0) {
243+
// not exactly 1 object
243244
goto fail;
244245
}
245246
vstr_clear(&vstr);

tests/extmod/ujson_loads.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ def my_print(o):
3333

3434
# whitespace handling
3535
my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}'))
36+
37+
# loading nothing should raise exception
38+
try:
39+
json.loads('')
40+
except ValueError:
41+
print('ValueError')

0 commit comments

Comments
 (0)