matrix-org / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://matrix-org.github.io/synapse
Apache License 2.0
11.79k stars 2.13k forks source link

Non-ascii characters like ™, Ö, ... in room name break admin list room api with UnicodeEncodeError: 'ascii' codec can't encode character #8210

Closed csett86 closed 4 years ago

csett86 commented 4 years ago

Description

If a room name contains non-ascii characters like "™", Ä, Ö, Ü, ... the admin list room api (GET /_synapse/admin/v1/rooms) fails with 500 internal server error when listing the rooms.

Steps to reproduce

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pacs/REDACTED/users/synod/synapse/env37/lib/python3.7/site-packages/twisted/internet/defer.py", line 1436, in _inlineCallbacks result = current_context.run(g.send, result) StopIteration: ([{'room_id': '!REDACTED:matrix.org', 'name': '', 'canonical_alias': None, 'joined_members': 3, 'joined_local_members': 1, 'version': '5', 'creator': '', 'encryption': None, 'federatable': True, 'public': False, 'join_rules': 'invite', 'guest_access': 'can_join', 'history_visibility': 'shared', 'state_events': 10}, ...], 1876)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pacs/REDACTED/users/synod/synapse/env37/lib/python3.7/site-packages/synapse/http/server.py", line 233, in _async_render_wrapper self._send_response(request, code, response) File "/home/pacs/REDACTED/users/synod/synapse/env37/lib/python3.7/site-packages/synapse/http/server.py", line 295, in _send_response canonical_json=self.canonical_json, File "/home/pacs/REDACTED/users/synod/synapse/env37/lib/python3.7/site-packages/synapse/http/server.py", line 536, in respond_with_json json_bytes = encode_pretty_printed_json(json_object) + b"\n" File "/home/pacs/REDACTED/users/synod/synapse/env37/lib/python3.7/site-packages/canonicaljson.py", line 96, in encode_pretty_printed_json return _pretty_encoder.encode(json_object).encode("ascii") UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 14266: ordinal not in range(128)



<!--
Describe how what happens differs from what you expected.

If you can identify any relevant log snippets from _homeserver.log_, please include
those (please be careful to remove any personal or private data). Please surround them with
``` (three backticks, on a line on their own), so that they are formatted legibly.
-->

### Version information

<!-- IMPORTANT: please answer the following questions, to help us narrow down the problem -->

<!-- Was this issue identified on matrix.org or another homeserver? -->
- **Homeserver**: synod.im

If not matrix.org:

<!--
 What version of Synapse is running?

You can find the Synapse version with this command:

$ curl http://localhost:8008/_synapse/admin/v1/server_version

(You may need to replace `localhost:8008` if Synapse is not configured to
listen on that port.)
-->
- **Version**: 1.19.1

- **Install method**: pip
<!-- examples: package manager/git clone/pip  -->

- **Platform**: Debian 10
<!--
Tell us about the environment in which your homeserver is operating
distro, hardware, if it's running in a vm/container, etc.
-->

Also on:

<!-- Was this issue identified on matrix.org or another homeserver? -->
- **Homeserver**: settgast.org

If not matrix.org:

<!--
 What version of Synapse is running?

You can find the Synapse version with this command:

$ curl http://localhost:8008/_synapse/admin/v1/server_version

(You may need to replace `localhost:8008` if Synapse is not configured to
listen on that port.)
-->
- **Version**: 1.19.1

- **Install method**: package manager
<!-- examples: package manager/git clone/pip  -->

- **Platform**: Ubuntu 18.04
<!--
Tell us about the environment in which your homeserver is operating
distro, hardware, if it's running in a vm/container, etc.
-->
csett86 commented 4 years ago

Duplicate of #8188, same workaround (use eg. the Synapse user-agent with curl) worked.