Skip to content

Commit

Permalink
writer: Fix hash entries not being sorted
Browse files Browse the repository at this point in the history
Keys were being sorted correctly but not the hash entries themselves...

This is required to avoid generating invalid documents as the official
BYML library performs binary searches.
  • Loading branch information
leoetlino committed Mar 17, 2019
1 parent 21db57c commit e528ec9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion byml/byml.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ def _write_nonvalue_node(self, stream: typing.BinaryIO, data, node_to_offset_map
elif isinstance(data, dict):
stream.write(self._u8(NodeType.HASH))
stream.write(self._u24(len(data)))
for (key, value) in data.items():
for key in sorted(data.keys()):
value = data[key]
stream.write(self._u24(self._hash_key_table[key]))
node_type = self._to_byml_type(value)
stream.write(self._u8(node_type))
Expand Down

0 comments on commit e528ec9

Please sign in to comment.