Bugfix/unmunge (#1688)

* Fix cases where the unmunge misses keywords

The unmunge would invariably miss keys due to the fact that the dict is modified while being iterated. This breaks out the keys into a list before iterating through them to ensure that all original keys are checked.

* Clean up the unmunge function slightly
pull/1696/head
Åke 2018-07-19 09:03:43 +02:00 committed by Steve Penrod
parent 031daac17b
commit ad5ebcf63d
1 changed files with 3 additions and 2 deletions

View File

@ -70,8 +70,9 @@ def unmunge_message(message, skill_id):
"""
if isinstance(message, Message) and isinstance(message.data, dict):
skill_id = to_alnum(skill_id)
for key in message.data:
if key[:len(skill_id)] == skill_id:
for key in list(message.data.keys()):
if key.startswith(skill_id):
# replace the munged key with the real one
new_key = key[len(skill_id):]
message.data[new_key] = message.data.pop(key)