Parse Content-Disposition headers more relaxed.
Before, we got an unhandled ValueError if there were multiple spaces in a filename. Instead of ignoring such a header altogether, we now add relaxed=True which still tries to get the filename in this situation (and with a semicolon at the line end). Because the parser is also more relaxed in that second case, we mark a test as expected failure.
This commit is contained in:
parent
e1f9403876
commit
8ce779261f
@ -251,6 +251,8 @@ class AttachmentTests(AttachmentTestCase):
|
||||
"""
|
||||
self._check_ignored('attachment; filename=foo,bar.html')
|
||||
|
||||
# With relaxed=True we accept that
|
||||
@unittest.expectedFailure
|
||||
def test_attwithasciifilenamenqs(self):
|
||||
"""'attachment', specifying a filename of foo.html.
|
||||
|
||||
@ -881,6 +883,16 @@ class RFC2047EncodingTests(AttachmentTestCase):
|
||||
'=?ISO-8859-1?Q?foo-=E4.html?=')
|
||||
|
||||
|
||||
class OurTests(AttachmentTestCase):
|
||||
|
||||
"""Our own tests, not based on http://greenbytes.de/tech/tc2231/"""
|
||||
|
||||
def test_att_double_space(self):
|
||||
"""'attachment' with double space in the filename."""
|
||||
self._check_filename('attachment; filename="foo bar.html"',
|
||||
'foo bar.html')
|
||||
|
||||
|
||||
def setUpModule():
|
||||
"""Mock out logging in utils."""
|
||||
utils.log = Mock()
|
||||
|
@ -322,7 +322,7 @@ def parse_content_disposition(reply):
|
||||
# os.path.basename later.
|
||||
try:
|
||||
content_disposition = rfc6266.parse_headers(
|
||||
bytes(reply.rawHeader('Content-Disposition')))
|
||||
bytes(reply.rawHeader('Content-Disposition')), relaxed=True)
|
||||
filename = content_disposition.filename_unsafe
|
||||
except UnicodeDecodeError as e:
|
||||
log.misc.warning("Error while getting filename: {}: {}".format(
|
||||
|
Loading…
Reference in New Issue
Block a user