Skip to content

Commit b336d27

Browse files
Proposal
1 parent 18bf8f8 commit b336d27

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Lib/http/server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,11 @@ def list_directory(self, path):
846846
except UnicodeDecodeError:
847847
displaypath = urllib.parse.unquote(self.path)
848848
displaypath = html.escape(displaypath, quote=False)
849-
enc = sys.getfilesystemencoding()
850849
title = f'Directory listing for {displaypath}'
851850
r.append('<!DOCTYPE HTML>')
852851
r.append('<html lang="en">')
853852
r.append('<head>')
854-
r.append(f'<meta charset="{enc}">')
853+
r.append('<meta charset="utf-8">')
855854
r.append('<style type="text/css">\n:root {\ncolor-scheme: light dark;\n}\n</style>')
856855
r.append(f'<title>{title}</title>\n</head>')
857856
r.append(f'<body>\n<h1>{title}</h1>')
@@ -871,12 +870,12 @@ def list_directory(self, path):
871870
errors='surrogatepass'),
872871
html.escape(displayname, quote=False)))
873872
r.append('</ul>\n<hr>\n</body>\n</html>\n')
874-
encoded = '\n'.join(r).encode(enc, 'surrogateescape')
873+
encoded = '\n'.join(r).encode('utf-8', 'surrogateescape')
875874
f = io.BytesIO()
876875
f.write(encoded)
877876
f.seek(0)
878877
self.send_response(HTTPStatus.OK)
879-
self.send_header("Content-type", "text/html; charset=%s" % enc)
878+
self.send_header("Content-type", "text/html; charset=utf-8")
880879
self.send_header("Content-Length", str(len(encoded)))
881880
self.end_headers()
882881
return f
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Encode file paths with utf-8 in :meth:`http.SimpleHTTPRequestHandler.list_directory`.

0 commit comments

Comments
 (0)