[issue22165] Empty response from http.server when directory listing contains invalid unicode

Senthil Kumaran report at bugs.python.org
Sun Aug 17 09:59:13 CEST 2014


Senthil Kumaran added the comment:

Looks like we hit with an encoding issue, which is due to way os.fsdecode() and os.listdir() decode the filenames.


>>> support.TESTFN_UNDECODABLE
b'@test_99678_tmp\xe7w\xf0'
>>> dir_list = os.listdir(self.tempdir)
>>> dir_list
['@test_99678_tmp%E7w%F0.txt', 'test']
>>> filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt'
>>> filename
'@test_99678_tmp\udce7w\udcf0.txt'


======================================================================
FAIL: test_undecodable_filename (test.test_httpservers.SimpleHTTPServerTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.4.murray-snowleopard/build/Lib/test/test_httpservers.py", line 282, in test_undecodable_filename
    .encode('utf-8', 'surrogateescape'), body)
AssertionError: b'href="%40test_62069_tmp%ED%B3%A7w%ED%B3%B0.txt"' not found in b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n<title>Directory listing for tmp0asrs9ei/</title>\n</head>\n<body>\n<h1>Directory listing for tmp0asrs9ei/</h1>\n<hr>\n<ul>\n<li><a href="%40test_62069_tmp%25E7w%25F0.txt">@test_62069_tmp%E7w%F0.txt</a></li>\n<li><a href="test">test</a></li>\n</ul>\n<hr>\n</body>\n</html>\n'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22165>
_______________________________________


More information about the Python-bugs-list mailing list