From 30c085fbc33e7ad47c31f28debd23bacaf41b599 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 19 Sep 2019 12:03:10 +0100 Subject: 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. --- synapse/types.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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_]") -- cgit 1.5.1