Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7122876
D2530.id9013.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D2530.id9013.diff
View Options
diff --git a/swh/web/browse/utils.py b/swh/web/browse/utils.py
--- a/swh/web/browse/utils.py
+++ b/swh/web/browse/utils.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2019 The Software Heritage developers
+# Copyright (C) 2017-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -280,14 +280,16 @@
if mime_type.startswith('image/'):
if mime_type in _browsers_supported_image_mimes:
- content_data = base64.b64encode(content_data)
- content_data = content_data.decode('utf-8')
+ content_data = base64.b64encode(content_data).decode('ascii')
else:
content_data = None
if mime_type.startswith('image/svg'):
mime_type = 'image/svg+xml'
+ if mime_type.startswith('text/'):
+ content_data = content_data.decode('utf-8', errors='replace')
+
return {'content_data': content_data,
'language': language,
'mimetype': mime_type}
diff --git a/swh/web/tests/browse/views/test_content.py b/swh/web/tests/browse/views/test_content.py
--- a/swh/web/tests/browse/views/test_content.py
+++ b/swh/web/tests/browse/views/test_content.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2019 The Software Heritage developers
+# Copyright (C) 2017-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -378,5 +378,9 @@
mime_type, encoding, content_data = _re_encode_content(
mime_type, encoding, content_data['data'])
- return prepare_content_for_display(content_data, mime_type,
- content['path'])
+ content_display = prepare_content_for_display(content_data, mime_type,
+ content['path'])
+
+ assert type(content_display['content_data']) == str
+
+ return content_display
diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py
--- a/swh/web/tests/browse/views/test_origin.py
+++ b/swh/web/tests/browse/views/test_origin.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2019 The Software Heritage developers
+# Copyright (C) 2017-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -564,6 +564,8 @@
assert resp.status_code == 200
assert_template_used(resp, 'browse/content.html')
+ assert type(content['data']) == str
+
assert_contains(resp, '<code class="%s">' %
content['hljs_language'])
assert_contains(resp, escape(content['data']))
diff --git a/swh/web/tests/data.py b/swh/web/tests/data.py
--- a/swh/web/tests/data.py
+++ b/swh/web/tests/data.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 The Software Heritage developers
+# Copyright (C) 2018-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -24,7 +24,8 @@
from swh.storage.algos.dir_iterators import dir_iterator
from swh.web import config
from swh.web.browse.utils import (
- get_mimetype_and_encoding_for_content, prepare_content_for_display
+ get_mimetype_and_encoding_for_content, prepare_content_for_display,
+ _re_encode_content
)
from swh.web.common import service
from swh.web.common.highlightjs import get_hljs_language_from_filename
@@ -241,6 +242,8 @@
cnt = next(storage.content_get([sha1]))
mimetype, encoding = get_mimetype_and_encoding_for_content(
cnt['data'])
+ _, _, cnt['data'] = _re_encode_content(
+ mimetype, encoding, cnt['data'])
content_display_data = prepare_content_for_display(
cnt['data'], mimetype, path)
contents[-1]['path'] = path
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 17, 9:06 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215684
Attached To
D2530: Decode textual content from utf-8 before displaying it
Event Timeline
Log In to Comment