diff --git a/Lib/http/server.py b/Lib/http/server.py index 2a9502870580..f916fdd95cbb 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -747,7 +747,12 @@ def list_directory(self, path): return None list.sort(key=lambda a: a.lower()) r = [] - displaypath = html.escape(urllib.parse.unquote(self.path)) + try: + displaypath = urllib.parse.unquote(self.path, + errors='surrogatepass') + except UnicodeDecodeError: + displaypath = urllib.parse.unquote(path) + displaypath = html.escape(displaypath) enc = sys.getfilesystemencoding() title = 'Directory listing for %s' % displaypath r.append('%s' - % (urllib.parse.quote(linkname), html.escape(displayname))) + % (urllib.parse.quote(linkname, + errors='surrogatepass'), + html.escape(displayname))) r.append('\n