Issue #22165: SimpleHTTPRequestHandler now supports undecodable file names.

This commit is contained in:
Serhiy Storchaka 2014-08-17 08:22:11 +03:00
parent 402df0975c
commit cb5bc408ad
3 changed files with 36 additions and 4 deletions

View file

@ -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