Skip to content

Commit

Permalink
Fix dealing with None types
Browse files Browse the repository at this point in the history
  • Loading branch information
mbish committed Oct 30, 2020
1 parent ed4cfe5 commit 7687b3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 7 additions & 5 deletions python/objToJSON.c
Expand Up @@ -258,7 +258,9 @@ static int Dict_iterNext(JSOBJ obj, JSONTypeContext *tc)
{
if (UNLIKELY(GET_TC(tc)->itemName == Py_None))
{
GET_TC(tc)->itemName = PyUnicode_FromString("null");
itemNameTmp = PyUnicode_FromString("null");
GET_TC(tc)->itemName = PyUnicode_AsUTF8String(itemNameTmp);
Py_DECREF(Py_None);
return 1;
}

Expand Down Expand Up @@ -537,17 +539,17 @@ static void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc, JSONObject
return;
}
else
if (PyFloat_Check(obj) || object_is_decimal_type(obj))
if (obj == Py_None)
{
PRINTMARK();
pc->PyTypeToJSON = PyFloatToDOUBLE; tc->type = JT_DOUBLE;
tc->type = JT_NULL;
return;
}
else
if (obj == Py_None)
if (PyFloat_Check(obj) || object_is_decimal_type(obj))
{
PRINTMARK();
tc->type = JT_NULL;
pc->PyTypeToJSON = PyFloatToDOUBLE; tc->type = JT_DOUBLE;
return;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/test_ujson.py
Expand Up @@ -806,6 +806,11 @@ def test_reject_bytes_false():
assert ujson.dumps(data, reject_bytes=False) == '{"a":"b"}'


def test_encode_none_key():
data = {None: None}
assert ujson.dumps(data) == '{"null":null}'


"""
def test_decode_numeric_int_frc_overflow():
input = "X.Y"
Expand Down

0 comments on commit 7687b3d

Please sign in to comment.