diff -r 089146b8ccc6 Lib/http/server.py --- a/Lib/http/server.py Fri Sep 25 00:49:44 2015 -0400 +++ b/Lib/http/server.py Fri Sep 25 23:10:53 2015 +0800 @@ -844,6 +844,12 @@ Raises: IndexError if too many '..' occur within the path. """ + # Query component should not be involved. + i = path.find('?') + if i >= 0: + path, query = path[:i], path[i+1:] + path = urllib.parse.unquote(path) + # Similar to os.path.split(os.path.normpath(path)) but specific to URL # path semantics rather than local operating system semantics. path_parts = path.split('/') @@ -864,6 +870,9 @@ else: tail_part = '' + if i >= 0: + tail_part = '?'.join((tail_part, query)) + splitpath = ('/' + '/'.join(head_parts), tail_part) collapsed_path = "/".join(splitpath) @@ -947,7 +956,7 @@ (and the next character is a '/' or the end of the string). """ - collapsed_path = _url_collapse_path(urllib.parse.unquote(self.path)) + collapsed_path = _url_collapse_path(self.path) dir_sep = collapsed_path.find('/', 1) head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:] if head in self.cgi_directories: