Skip to content

Commit 4e04c8c

Browse files
fix: enforce strict_map_key with object_pairs_hook
1 parent 0d600a3 commit 4e04c8c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

msgpack/fallback.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,13 @@ def _unpack(self, execute=EX_CONSTRUCT):
518518
self._unpack(EX_SKIP)
519519
return
520520
if self._object_pairs_hook is not None:
521-
ret = self._object_pairs_hook(
522-
(self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT)) for _ in range(n)
523-
)
521+
def _gen():
522+
for _ in range(n):
523+
key = self._unpack(EX_CONSTRUCT)
524+
if self._strict_map_key and type(key) not in (str, bytes):
525+
raise ValueError("%s is not allowed for map key" % str(type(key)))
526+
yield key, self._unpack(EX_CONSTRUCT)
527+
ret = self._object_pairs_hook(_gen())
524528
else:
525529
ret = {}
526530
for _ in range(n):

0 commit comments

Comments
 (0)