]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] gh-100474: Fix handling of dirs named index.html in http.server (GH-100504)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 24 Dec 2022 20:29:21 +0000 (12:29 -0800)
committerGitHub <noreply@github.com>
Sat, 24 Dec 2022 20:29:21 +0000 (15:29 -0500)
Co-authored-by: James Frost <git@frost.cx>
Lib/http/server.py
Lib/test/test_httpservers.py
Misc/NEWS.d/next/Library/2022-12-23-21-02-43.gh-issue-100474.gppA4U.rst [new file with mode: 0644]

index 03dbaa51b798b750b009990a13b9d45ac91b1e4e..9c218d06acf5c5fafbfd6fc6435aa8cd584cc3e0 100644 (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:
index ac8da494e9bb838325f47f424c8bcaa5f7cc0f8b..a5f787ff48c93b67e85e658eb84a7eed1903bb77 100644 (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:
diff --git a/Misc/NEWS.d/next/Library/2022-12-23-21-02-43.gh-issue-100474.gppA4U.rst b/Misc/NEWS.d/next/Library/2022-12-23-21-02-43.gh-issue-100474.gppA4U.rst
new file mode 100644 (file)
index 0000000..31abfb8
--- /dev/null
@@ -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``.