From: Senthil Kumaran Date: Fri, 13 Sep 2013 07:21:18 +0000 (-0700) Subject: Fix http.server's request handling case on trailing '/'. X-Git-Tag: v3.4.0a3~82^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72c238e21ae78f8da969c46a2b7317ff9904d155;p=python Fix http.server's request handling case on trailing '/'. Patch contributed by Vajrasky Kok. Addresses Issue #17324 --- diff --git a/Lib/http/server.py b/Lib/http/server.py index c4ac703d2d..195f9ee36b 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -780,6 +780,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): # abandon query parameters path = path.split('?',1)[0] path = path.split('#',1)[0] + # Don't forget explicit trailing slash when normalizing. Issue17324 + trailing_slash = True if path.rstrip().endswith('/') else False path = posixpath.normpath(urllib.parse.unquote(path)) words = path.split('/') words = filter(None, words) @@ -789,6 +791,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): head, word = os.path.split(word) if word in (os.curdir, os.pardir): continue path = os.path.join(path, word) + if trailing_slash: + path += '/' return path def copyfile(self, source, outputfile): diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index 03c0776ce5..b8bbcb6734 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -249,6 +249,9 @@ class SimpleHTTPServerTestCase(BaseTestCase): #constructs the path relative to the root directory of the HTTPServer response = self.request(self.tempdir_name + '/test') self.check_status_and_reason(response, 200, data=self.data) + # check for trailing "/" which should return 404. See Issue17324 + response = self.request(self.tempdir_name + '/test/') + self.check_status_and_reason(response, 404) response = self.request(self.tempdir_name + '/') self.check_status_and_reason(response, 200) response = self.request(self.tempdir_name) diff --git a/Misc/NEWS b/Misc/NEWS index 3d9f24d718..1655238181 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -68,6 +68,10 @@ Core and Builtins Library ------- + +- Issue #17324: Fix http.server's request handling case on trailing '/'. Patch + contributed by Vajrasky Kok. + - Issue #18784: The uuid module no more attempts to load libc via ctypes.CDLL, if all necessary functions are already found in libuuid. Patch by Evgeny Sologubov.