mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-34711: Return HTTPStatus.NOT_FOUND if path.endswith('/') and not a directory (GH-9687)
AIX allows a trailing slash on local file system paths, which isn't what we want in http.server. Accordingly, check explicitly for this case in the server code, rather than relying on the OS raising an exception. Patch by Michael Felt.
This commit is contained in:
parent
22462da70c
commit
2062a20641
2 changed files with 11 additions and 0 deletions
|
@ -692,6 +692,14 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
|||
else:
|
||||
return self.list_directory(path)
|
||||
ctype = self.guess_type(path)
|
||||
# check for trailing "/" which should return 404. See Issue17324
|
||||
# The test for this was added in test_httpserver.py
|
||||
# However, some OS platforms accept a trailingSlash as a filename
|
||||
# See discussion on python-dev and Issue34711 regarding
|
||||
# parseing and rejection of filenames with a trailing slash
|
||||
if path.endswith("/"):
|
||||
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
|
||||
return None
|
||||
try:
|
||||
f = open(path, 'rb')
|
||||
except OSError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue