summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2019-09-09 17:52:05 +0100
committerGitHub <noreply@github.com>2019-09-09 17:52:05 +0100
commit43c1a10e91137a967474be8551ef6ae75a79285f (patch)
treed20b97cea7cce0d8df3df6368b6bf952905d8fdb
parentMerge pull request #1 from matrix-org/babolivier/direct-avatar-name (diff)
parentRename io.open import to limite side-effects (diff)
downloadsynapse-43c1a10e91137a967474be8551ef6ae75a79285f.tar.xz
Merge pull request #3 from matrix-org/babolivier/password-reset-template-unicode
Ensure the password reset template is correctly converted to binary
-rw-r--r--changelog.d/3.bugfix1
-rw-r--r--synapse/config/_base.py3
-rw-r--r--synapse/python_dependencies.py2
-rw-r--r--synapse/rest/client/v2_alpha/account_validity.py4
-rw-r--r--tests/rest/client/v2_alpha/test_register.py5
5 files changed, 7 insertions, 8 deletions
diff --git a/changelog.d/3.bugfix b/changelog.d/3.bugfix
new file mode 100644

index 0000000000..cc4bcefa80 --- /dev/null +++ b/changelog.d/3.bugfix
@@ -0,0 +1 @@ +Fix encoding on password reset HTML responses in Python 2. diff --git a/synapse/config/_base.py b/synapse/config/_base.py
index f7d7f153bb..bf039e5823 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py
@@ -16,6 +16,7 @@ import argparse import errno import os +from io import open as io_open from textwrap import dedent from six import integer_types @@ -131,7 +132,7 @@ class Config(object): @classmethod def read_file(cls, file_path, config_name): cls.check_file(file_path, config_name) - with open(file_path) as file_stream: + with io_open(file_path, encoding="utf-8") as file_stream: return file_stream.read() @staticmethod diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py
index 9692f0bf75..7dfa78dadb 100644 --- a/synapse/python_dependencies.py +++ b/synapse/python_dependencies.py
@@ -67,7 +67,7 @@ REQUIREMENTS = [ "pymacaroons>=0.13.0", "msgpack>=0.5.0", "phonenumbers>=8.2.0", - "six>=1.12", + "six>=1.10", # prometheus_client 0.4.0 changed the format of counter metrics # (cf https://github.com/matrix-org/synapse/issues/4001) "prometheus_client>=0.0.18,<0.4.0", diff --git a/synapse/rest/client/v2_alpha/account_validity.py b/synapse/rest/client/v2_alpha/account_validity.py
index 98f7c60016..8091b78285 100644 --- a/synapse/rest/client/v2_alpha/account_validity.py +++ b/synapse/rest/client/v2_alpha/account_validity.py
@@ -15,8 +15,6 @@ import logging -from six import ensure_binary - from twisted.internet import defer from synapse.api.errors import AuthError, SynapseError @@ -65,7 +63,7 @@ class AccountValidityRenewServlet(RestServlet): request.setResponseCode(status_code) request.setHeader(b"Content-Type", b"text/html; charset=utf-8") request.setHeader(b"Content-Length", b"%d" % (len(response),)) - request.write(ensure_binary(response)) + request.write(response.encode("utf8")) finish_request(request) defer.returnValue(None) diff --git a/tests/rest/client/v2_alpha/test_register.py b/tests/rest/client/v2_alpha/test_register.py
index b28de3663c..af1e600591 100644 --- a/tests/rest/client/v2_alpha/test_register.py +++ b/tests/rest/client/v2_alpha/test_register.py
@@ -20,7 +20,6 @@ import json import os from mock import Mock -from six import ensure_binary import pkg_resources @@ -438,7 +437,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase): # Check that the HTML we're getting is the one we expect on a successful renewal. expected_html = self.hs.config.account_validity.account_renewed_html_content self.assertEqual( - channel.result["body"], ensure_binary(expected_html), channel.result + channel.result["body"], expected_html.encode("utf8"), channel.result ) # Move 3 days forward. If the renewal failed, every authed request with @@ -468,7 +467,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase): # invalid/unknown token. expected_html = self.hs.config.account_validity.invalid_token_html_content self.assertEqual( - channel.result["body"], ensure_binary(expected_html), channel.result + channel.result["body"], expected_html.encode("utf8"), channel.result ) def test_manual_email_send(self):