summary refs log tree commit diff
path: root/synapse/util/stringutils.py
diff options
context:
space:
mode:
authorhera <matrix@template.upcloud.com>2018-08-21 19:12:14 +0000
committerhera <matrix@template.upcloud.com>2018-08-21 19:12:14 +0000
commitd1065e6f512447e6ba9dc4beddf26695880023e1 (patch)
tree4c54a1e7e9f62bda2689bd47f69d65708fd3b7c8 /synapse/util/stringutils.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes (diff)
parentchangelog (diff)
downloadsynapse-d1065e6f512447e6ba9dc4beddf26695880023e1.tar.xz
Merge tag 'v0.33.3rc2' into matrix-org-hotfixes
Bugfixes
--------

- Fix bug in v0.33.3rc1 which caused infinite loops and OOMs
([\#3723](https://github.com/matrix-org/synapse/issues/3723))
Diffstat (limited to 'synapse/util/stringutils.py')
-rw-r--r--synapse/util/stringutils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py

index 43d9db67ec..6f318c6a29 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py
@@ -16,6 +16,7 @@ import random import string +from six import PY3 from six.moves import range _string_with_symbols = ( @@ -34,6 +35,17 @@ def random_string_with_symbols(length): def is_ascii(s): + + if PY3: + if isinstance(s, bytes): + try: + s.decode('ascii').encode('ascii') + except UnicodeDecodeError: + return False + except UnicodeEncodeError: + return False + return True + try: s.encode("ascii") except UnicodeEncodeError: @@ -49,6 +61,9 @@ def to_ascii(s): If given None then will return None. """ + if PY3: + return s + if s is None: return None