summaryrefslogtreecommitdiff
path: root/msgpack/unpack.h
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2018-11-30 11:47:15 +0900
committerGitHub <noreply@github.com>2018-11-30 11:47:15 +0900
commit760e30b77e4ec26dbfebb9c5adbd43933fca18bc (patch)
tree69294aedf5c7b313593fc3f9f566659957312f25 /msgpack/unpack.h
parent3c9c6edbc88908fceb3c69ff3d6455be8b5914c8 (diff)
parent8ae6320072e746fad29bc14a095569811e009695 (diff)
downloadmsgpack-python-760e30b77e4ec26dbfebb9c5adbd43933fca18bc.tar.gz
unpacker: Add `strict_map_key` option (#334)
Diffstat (limited to 'msgpack/unpack.h')
-rw-r--r--msgpack/unpack.h5
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)