UnicodeDecodeError in apps/common/middleware/strip_spaces_widdleware.py
Steps to reproduce: fresh installation. Create a new tag. Click on ACL for this tag.
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/acls/tags/tag/1/list/
Django Version: 1.7.10
Python Version: 2.7.9
Traceback:
File "/home/xael/python.venvs/mayandev/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
204. response = middleware_method(request, response)
File "/tmp/mayan-edms/mayan/apps/common/middleware/strip_spaces_widdleware.py" in process_response
12. if 'text/html' in response.get('Content-Type', ''):
Exception Type: UnicodeDecodeError at /acls/tags/tag/1/list/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
Environment used is in french locale so 'Tag' is translated as 'Étiquette' with a non-ascii letter.
The same occurs with folders, translated as 'Répertoire'.
The error occurs in apps/common/middleware/strip_spaces_widdleware.py
. Changing it to
def process_response(self, request, response):
if 'text/html' in response.get('Content-Type', '').decode('utf-8'):
response.content = strip_spaces_between_tags(response.content)
return response
make it works as intended.
Patch proposal:
diff --git a/mayan/apps/common/middleware/strip_spaces_widdleware.py b/mayan/apps/common/middleware/strip_spaces_widdleware.py
index b6d4a0b..4df70b8 100644
--- a/mayan/apps/common/middleware/strip_spaces_widdleware.py
+++ b/mayan/apps/common/middleware/strip_spaces_widdleware.py
@@ -9,6 +9,6 @@ class SpacelessMiddleware(object):
"""
def process_response(self, request, response):
- if 'text/html' in response.get('Content-Type', ''):
+ if 'text/html' in response.get('Content-Type', '').decode('utf-8'):
response.content = strip_spaces_between_tags(response.content)
return response
Anyway instead of manually remove spaces, I would rely on spaceless in templates: https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#spaceless