Commit 187b0630 authored by Senthil Kumaran's avatar Senthil Kumaran

Fix http.server's request handling case on trailing '/'.

Patch contributed by Vajrasky Kok. Addresses Issue #17324
parents 5abf3d99 72c238e2
...@@ -788,6 +788,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): ...@@ -788,6 +788,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
# abandon query parameters # abandon query parameters
path = path.split('?',1)[0] path = path.split('?',1)[0]
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)) path = posixpath.normpath(urllib.parse.unquote(path))
words = path.split('/') words = path.split('/')
words = filter(None, words) words = filter(None, words)
...@@ -797,6 +799,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): ...@@ -797,6 +799,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
head, word = os.path.split(word) head, word = os.path.split(word)
if word in (os.curdir, os.pardir): continue if word in (os.curdir, os.pardir): continue
path = os.path.join(path, word) path = os.path.join(path, word)
if trailing_slash:
path += '/'
return path return path
def copyfile(self, source, outputfile): def copyfile(self, source, outputfile):
......
...@@ -270,6 +270,9 @@ class SimpleHTTPServerTestCase(BaseTestCase): ...@@ -270,6 +270,9 @@ class SimpleHTTPServerTestCase(BaseTestCase):
#constructs the path relative to the root directory of the HTTPServer #constructs the path relative to the root directory of the HTTPServer
response = self.request(self.tempdir_name + '/test') response = self.request(self.tempdir_name + '/test')
self.check_status_and_reason(response, 200, data=self.data) 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 + '/') response = self.request(self.tempdir_name + '/')
self.check_status_and_reason(response, 200) self.check_status_and_reason(response, 200)
response = self.request(self.tempdir_name) response = self.request(self.tempdir_name)
......
...@@ -10,6 +10,10 @@ Core and Builtins ...@@ -10,6 +10,10 @@ Core and Builtins
Library 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, - Issue #18784: The uuid module no more attempts to load libc via ctypes.CDLL,
if all necessary functions are already found in libuuid. if all necessary functions are already found in libuuid.
Patch by Evgeny Sologubov. Patch by Evgeny Sologubov.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment