[3.10] gh-100474: Fix handling of dirs named index.html in http.server (GH-100504)

Co-authored-by: James Frost <git@frost.cx>
This commit is contained in:
Miss Islington (bot) 2022-12-24 12:29:21 -08:00 committed by GitHub
parent 0dea92409e
commit ecbf136702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

View file

@ -709,7 +709,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
return None
for index in "index.html", "index.htm":
index = os.path.join(path, index)
if os.path.exists(index):
if os.path.isfile(index):
path = index
break
else:

View file

@ -488,6 +488,9 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
response = self.request('/' + 'ThisDoesNotExist' + '/')
self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
os.makedirs(os.path.join(self.tempdir, 'spam', 'index.html'))
response = self.request(self.base_url + '/spam/')
self.check_status_and_reason(response, HTTPStatus.OK)
data = b"Dummy index file\r\n"
with open(os.path.join(self.tempdir_name, 'index.html'), 'wb') as f:

View file

@ -0,0 +1,2 @@
:mod:`http.server` now checks that an index page is actually a regular file before trying
to serve it. This avoids issues with directories named ``index.html``.