Commit 0e4340b1 authored by Johannes Gijsbers's avatar Johannes Gijsbers

Patch #1011123: Use urllib.quote() instead of cgi.escape() for encoding the

href attribute in list_directory(). This fixes the links for legal Unix
filenames such as 'a"b'.
parent 9f912527
...@@ -105,7 +105,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -105,7 +105,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
f.write("<hr>\n<ul>\n") f.write("<hr>\n<ul>\n")
for name in list: for name in list:
fullname = os.path.join(path, name) fullname = os.path.join(path, name)
displayname = linkname = name = cgi.escape(name) displayname = linkname = name
# Append / for directories or @ for symbolic links # Append / for directories or @ for symbolic links
if os.path.isdir(fullname): if os.path.isdir(fullname):
displayname = name + "/" displayname = name + "/"
...@@ -113,7 +113,8 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -113,7 +113,8 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
if os.path.islink(fullname): if os.path.islink(fullname):
displayname = name + "@" displayname = name + "@"
# Note: a link to a directory displays with @ and links with / # Note: a link to a directory displays with @ and links with /
f.write('<li><a href="%s">%s</a>\n' % (linkname, displayname)) f.write('<li><a href="%s">%s</a>\n'
% (urllib.quote(linkname), cgi.escape(displayname)))
f.write("</ul>\n<hr>\n") f.write("</ul>\n<hr>\n")
length = f.tell() length = f.tell()
f.seek(0) f.seek(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment