diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2025-05-17 07:37:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-17 07:37:43 (GMT) |
commit | d7230e1110f9dd210596349e09c5824862666b5b (patch) | |
tree | c2d9377d3ff4a4caf34aad636190b464434449e6 /Lib/http/server.py | |
parent | 5cdad8c90caa4efbd7846764a37d08402cd5812c (diff) | |
download | cpython-d7230e1110f9dd210596349e09c5824862666b5b.zip cpython-d7230e1110f9dd210596349e09c5824862666b5b.tar.gz cpython-d7230e1110f9dd210596349e09c5824862666b5b.tar.bz2 |
[3.14] gh-134098: Fix handling %-encoded trailing slash in SimpleHTTPRequestHandler (GH-134099) (GH-134123)
(cherry picked from commit 2f1ecb3bc474a5895dce090cca7b8afe7b560040)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/http/server.py')
-rw-r--r-- | Lib/http/server.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py index 64f766f..8be1903 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -750,7 +750,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): f = None if os.path.isdir(path): parts = urllib.parse.urlsplit(self.path) - if not parts.path.endswith('/'): + if not parts.path.endswith(('/', '%2f', '%2F')): # redirect browser - doing basically what apache does self.send_response(HTTPStatus.MOVED_PERMANENTLY) new_parts = (parts[0], parts[1], parts[2] + '/', @@ -890,14 +890,14 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): """ # 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 = path.rstrip().endswith('/') try: path = urllib.parse.unquote(path, errors='surrogatepass') except UnicodeDecodeError: path = urllib.parse.unquote(path) + trailing_slash = path.endswith('/') path = posixpath.normpath(path) words = path.split('/') words = filter(None, words) |