diff options
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 |