diff options
Diffstat (limited to 'cherrypy/test/test_static.py')
-rw-r--r-- | cherrypy/test/test_static.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cherrypy/test/test_static.py b/cherrypy/test/test_static.py index 3de658af..42c2fdee 100644 --- a/cherrypy/test/test_static.py +++ b/cherrypy/test/test_static.py @@ -97,6 +97,22 @@ 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): + file_path = os.path.join(curdir, 'style.css') + return static.serve_file( + file_path, + disposition='attachment', + name='has_utf-8_character_☃.html') + + @cherrypy.expose + def serve_fileobj_utf8_filename(self): + f = open(os.path.join(curdir, 'style.css'), 'rb') + return static.serve_fileobj( + f, + disposition='attachment', + name='has_utf-8_character_☃.html') + class Static: @cherrypy.expose @@ -193,6 +209,19 @@ 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' + cd = '''attachment; filename="%s"; filename*=UTF-8\'\'%s''' + + self.getPage('/serve_file_utf8_filename') + self.assertStatus('200 OK') + self.assertHeader('Content-Disposition', cd % (ascii_fn, url_quote_fn)) + + self.getPage('/serve_fileobj_utf8_filename') + self.assertStatus('200 OK') + self.assertHeader('Content-Disposition', cd % (ascii_fn, url_quote_fn)) + @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 |