You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2023/03/03 15:22:36 UTC

[allura] branch master updated: further fix for latin1 in etag headers

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/master by this push:
     new 95a6ab16a further fix for latin1 in etag headers
95a6ab16a is described below

commit 95a6ab16aaccf8aaecf1a7f14f538689c4a7b951
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Fri Mar 3 10:22:29 2023 -0500

    further fix for latin1 in etag headers
---
 Allura/allura/lib/utils.py                   | 2 +-
 Allura/allura/tests/model/test_filesystem.py | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 496ecf101..396ad7ccf 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -520,7 +520,7 @@ def serve_file(fp, filename, content_type, last_modified=None,
     '''Sets the response headers and serves as a wsgi iter'''
     if not etag and filename and last_modified:
         # must be latin1, no unicode
-        etag = filename.encode("latin1", "backslashreplace").decode() + f'?{last_modified}'
+        etag = filename.encode("latin1", "backslashreplace").decode('latin1') + f'?{last_modified}'
     if etag:
         etag_cache(etag)
     tg.response.headers['Content-Type'] = ''
diff --git a/Allura/allura/tests/model/test_filesystem.py b/Allura/allura/tests/model/test_filesystem.py
index 2efbff0c8..7c2c9520a 100644
--- a/Allura/allura/tests/model/test_filesystem.py
+++ b/Allura/allura/tests/model/test_filesystem.py
@@ -124,7 +124,7 @@ class TestFile(TestCase):
         self._assert_content(f, b'test2')
 
     def test_serve_embed(self):
-        f = File.from_data('te s\u0b6e1.txt', b'test1')
+        f = File.from_data('te s\u0b6e1\xe9.txt', b'test1')
         self.session.flush()
         with patch('allura.lib.utils.tg.request', Request.blank('/')), \
                 patch('allura.lib.utils.tg.response', Response()) as response, \
@@ -132,7 +132,7 @@ class TestFile(TestCase):
             response_body = list(f.serve())
             etag_val = etag_cache.call_args[0][0]
             etag_val.encode('latin1')  # ensure it is all latin1 and OK for a http header (no unicode!)
-            assert etag_val == '{}?{}'.format(r'te s\u0b6e1.txt', f._id.generation_time)
+            assert etag_val == '{}?{}'.format(r'te s\u0b6e1é.txt', f._id.generation_time)
             assert [b'test1'] == response_body
             assert response.content_type == f.content_type
             assert 'Content-Disposition' not in response.headers