summaryrefslogtreecommitdiff
path: root/cherrypy/test
diff options
context:
space:
mode:
authorSviatoslav Sydorenko <wk@sydorenko.org.ua>2020-04-17 19:49:39 +0200
committerSviatoslav Sydorenko <wk@sydorenko.org.ua>2020-04-17 19:49:39 +0200
commitb2938bc92570a1a04aa4336412e1824b9fe455eb (patch)
treec5fafefb4bdc8a555082eb4970b603263a8cfbfb /cherrypy/test
parentf17397ec648f48a6969268abb5486f727c7de98f (diff)
parentbc1dd5a5d9be7ad613a6b23ac83938936a4509a9 (diff)
downloadcherrypy-git-18.6.0.tar.gz
Merge remote-tracking branch 'origin/pr/1851'v18.6.0
This change implements serving files with Unicode in their names. This is achieved adding extra `filename*` parameter in `Content-Disposition` header when serving content with non-ASCII filenames. As per RFC 6266 recommendations in the Appendix D. Refs: * https://stackoverflow.com/a/8996249/2173868 * https://tools.ietf.org/html/rfc6266#appendix-D Resolves #1776
Diffstat (limited to 'cherrypy/test')
-rw-r--r--cherrypy/test/test_static.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/cherrypy/test/test_static.py b/cherrypy/test/test_static.py
index 3de658af..bfe2f40f 100644
--- a/cherrypy/test/test_static.py
+++ b/cherrypy/test/test_static.py
@@ -97,6 +97,20 @@ class StaticTest(helper.CPWebCase):
f = io.BytesIO(b'Fee\nfie\nfo\nfum')
return static.serve_fileobj(f, content_type='text/plain')
+ @cherrypy.expose
+ def serve_file_utf8_filename(self):
+ return static.serve_file(
+ __file__,
+ disposition='attachment',
+ name='has_utf-8_character_☃.html')
+
+ @cherrypy.expose
+ def serve_fileobj_utf8_filename(self):
+ return static.serve_fileobj(
+ io.BytesIO('☃\nfie\nfo\nfum'.encode('utf-8')),
+ disposition='attachment',
+ name='has_utf-8_character_☃.html')
+
class Static:
@cherrypy.expose
@@ -193,6 +207,22 @@ class StaticTest(helper.CPWebCase):
# we just check the content
self.assertMatchesBody('^Dummy stylesheet')
+ # Check a filename with utf-8 characters in it
+ ascii_fn = 'has_utf-8_character_.html'
+ url_quote_fn = 'has_utf-8_character_%E2%98%83.html' # %E2%98%83 == ☃
+ expected_content_disposition = (
+ 'attachment; filename="{!s}"; filename*=UTF-8\'\'{!s}'.
+ format(ascii_fn, url_quote_fn)
+ )
+
+ self.getPage('/serve_file_utf8_filename')
+ self.assertStatus('200 OK')
+ self.assertHeader('Content-Disposition', expected_content_disposition)
+
+ self.getPage('/serve_fileobj_utf8_filename')
+ self.assertStatus('200 OK')
+ self.assertHeader('Content-Disposition', expected_content_disposition)
+
@pytest.mark.skipif(platform.system() != 'Windows', reason='Windows only')
def test_static_longpath(self):
"""Test serving of a file in subdir of a Windows long-path