diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-08-17 05:22:11 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-08-17 05:22:11 (GMT) |
commit | cb5bc408ad525c695b00bf78fdf69c24028fed96 (patch) | |
tree | ab375d8444a09cb88f37162dd1730f2662c643b7 /Lib/test/test_httpservers.py | |
parent | 402df0975c1adacdc3673b9308ec759a557f6b4b (diff) | |
download | cpython-cb5bc408ad525c695b00bf78fdf69c24028fed96.zip cpython-cb5bc408ad525c695b00bf78fdf69c24028fed96.tar.gz cpython-cb5bc408ad525c695b00bf78fdf69c24028fed96.tar.bz2 |
Issue #22165: SimpleHTTPRequestHandler now supports undecodable file names.
Diffstat (limited to 'Lib/test/test_httpservers.py')
-rw-r--r-- | Lib/test/test_httpservers.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index 0f4b9ba..8c22651 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -14,6 +14,7 @@ import re import base64 import shutil import urllib.parse +import html import http.client import tempfile from io import BytesIO @@ -266,6 +267,24 @@ class SimpleHTTPServerTestCase(BaseTestCase): self.assertIsNotNone(response.reason) if data: self.assertEqual(data, body) + return body + + @unittest.skipUnless(support.TESTFN_UNDECODABLE, + 'need support.TESTFN_UNDECODABLE') + def test_undecodable_filename(self): + filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt' + with open(os.path.join(self.tempdir, filename), 'wb') as f: + f.write(support.TESTFN_UNDECODABLE) + response = self.request(self.tempdir_name + '/') + body = self.check_status_and_reason(response, 200) + quotedname = urllib.parse.quote(filename, errors='surrogatepass') + self.assertIn(('href="%s"' % quotedname) + .encode('utf-8', 'surrogateescape'), body) + self.assertIn(('>%s<' % html.escape(filename)) + .encode('utf-8', 'surrogateescape'), body) + response = self.request(self.tempdir_name + '/' + quotedname) + self.check_status_and_reason(response, 200, + data=support.TESTFN_UNDECODABLE) def test_get(self): #constructs the path relative to the root directory of the HTTPServer |