diff --git a/Lib/http/server.py b/Lib/http/server.py
index e571418cc00..b79d191fbb4 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -105,6 +105,7 @@ import copy
DEFAULT_ERROR_MESSAGE = """\
+
Error response
@@ -734,10 +735,16 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
list.sort(key=lambda a: a.lower())
r = []
displaypath = html.escape(urllib.parse.unquote(self.path))
- r.append('')
- r.append("\nDirectory listing for %s\n" % displaypath)
- r.append("\nDirectory listing for %s
\n" % displaypath)
- r.append("
\n\n")
+ enc = sys.getfilesystemencoding()
+ title = 'Directory listing for %s' % displaypath
+ r.append('')
+ r.append('\n')
+ r.append('' % enc)
+ r.append('%s\n' % title)
+ r.append('\n%s
' % title)
+ r.append('
\n')
for name in list:
fullname = os.path.join(path, name)
displayname = linkname = name
@@ -748,11 +755,10 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
if os.path.islink(fullname):
displayname = name + "@"
# Note: a link to a directory displays with @ and links with /
- r.append('- %s\n'
+ r.append('
- %s
'
% (urllib.parse.quote(linkname), html.escape(displayname)))
- r.append("
\n
\n\n\n")
- enc = sys.getfilesystemencoding()
- encoded = ''.join(r).encode(enc)
+ r.append('
\n
\n\n\n')
+ encoded = '\n'.join(r).encode(enc)
f = io.BytesIO()
f.write(encoded)
f.seek(0)
diff --git a/Misc/NEWS b/Misc/NEWS
index 3cd76218fe1..c751ba689c7 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -350,6 +350,8 @@ Core and Builtins
Library
-------
+- Issue #13295: http.server now produces valid HTML 4.01 strict.
+
- Issue #2892: preserve iterparse events in case of SyntaxError.
- Issue #13287: urllib.request and urllib.error now contains a __all__ and