summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2019-09-19 12:03:10 +0100
committerBrendan Abolivier <babolivier@matrix.org>2019-09-19 12:03:10 +0100
commit30c085fbc33e7ad47c31f28debd23bacaf41b599 (patch)
tree7c7c01553364b48f99e1091c8b4e31520b97ef86
parentAdd unit tests for strip_invalid_mxid_characters (diff)
downloadsynapse-30c085fbc33e7ad47c31f28debd23bacaf41b599.tar.xz
Use six.moves.filter when filtering out from MXID
Python 2's filter() function and Python 3's don't return the same type when processing a string (respectively str and filter), therefore use six's compatibility mapping (which resolves to itertools.ifilter() if using Python2), then generate a string from the filtered list, in order to ensure consistent behaviour between Python 2 and Python 3.
-rw-r--r--synapse/types.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/synapse/types.py b/synapse/types.py

index eebe29d1f0..842275e0fa 100644 --- a/synapse/types.py +++ b/synapse/types.py
@@ -17,6 +17,7 @@ import string from collections import namedtuple import attr +from six.moves import filter from synapse.api.errors import SynapseError @@ -240,7 +241,8 @@ def strip_invalid_mxid_characters(localpart): Returns: localpart (basestring): the localpart having been stripped """ - return filter(lambda c: c in mxid_localpart_allowed_characters, localpart) + filtered = filter(lambda c: c in mxid_localpart_allowed_characters, localpart) + return "".join(list(filtered)) UPPER_CASE_PATTERN = re.compile(b"[A-Z_]")