diff options
| author | Inada Naoki <songofacandy@gmail.com> | 2018-11-29 22:29:38 +0900 |
|---|---|---|
| committer | Inada Naoki <songofacandy@gmail.com> | 2018-11-29 22:29:38 +0900 |
| commit | e9086a34e4b3d64df78314339f152c800e79c8e1 (patch) | |
| tree | d4b46ab4c67c7195d3370829b57e1ac692f2cedb /msgpack/unpack.h | |
| parent | 3c9c6edbc88908fceb3c69ff3d6455be8b5914c8 (diff) | |
| download | msgpack-python-e9086a34e4b3d64df78314339f152c800e79c8e1.tar.gz | |
Add strict_map_key option to unpacker
Diffstat (limited to 'msgpack/unpack.h')
| -rw-r--r-- | msgpack/unpack.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 63e5543..85dbbed 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -23,6 +23,7 @@ typedef struct unpack_user { bool use_list; bool raw; bool has_pairs_hook; + bool strict_map_key; PyObject *object_hook; PyObject *list_hook; PyObject *ext_hook; @@ -188,6 +189,10 @@ static inline int unpack_callback_map(unpack_user* u, unsigned int n, msgpack_un static inline int unpack_callback_map_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) { + if (u->strict_map_key && !PyUnicode_CheckExact(k) && !PyBytes_CheckExact(k)) { + PyErr_Format(PyExc_ValueError, "%.100s is not allowed for map key", Py_TYPE(k)->tp_name); + return -1; + } if (u->has_pairs_hook) { msgpack_unpack_object item = PyTuple_Pack(2, k, v); if (!item) |
