diff options
author | James Frost <git@frost.cx> | 2022-12-24 18:28:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 18:28:59 (GMT) |
commit | 46e6a28308def2c3a71c679a6fa4ed7d520802b9 (patch) | |
tree | b2b2c299b224765262b01e8bf280e5f692c95599 /Lib | |
parent | 00afa5066bd45348ed82a38d3442763b2ed1a068 (diff) | |
download | cpython-46e6a28308def2c3a71c679a6fa4ed7d520802b9.zip cpython-46e6a28308def2c3a71c679a6fa4ed7d520802b9.tar.gz cpython-46e6a28308def2c3a71c679a6fa4ed7d520802b9.tar.bz2 |
gh-100474: Fix handling of dirs named index.html in http.server (GH-100475)
If you had a directory called index.html or index.htm within a directory, it would cause http.server to return a 404 Not Found error instead of the directory listing. This came about due to not checking that the index was a regular file.
I have also added a test case for this situation.
Automerge-Triggered-By: GH:merwok
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/http/server.py | 2 | ||||
-rw-r--r-- | Lib/test/test_httpservers.py | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py index 8acabff..221c8be 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -711,7 +711,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): return None for index in self.index_pages: index = os.path.join(path, index) - if os.path.exists(index): + if os.path.isfile(index): path = index break else: diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index ca07886..cbcf941 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -489,6 +489,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: |