More graceful handling of malformed Content-Disposition

This commit is contained in:
Tom Christie 2015-01-23 12:26:44 +00:00
parent 4cb164b66c
commit f1ac9d3f9b
2 changed files with 4 additions and 2 deletions

View File

@ -298,7 +298,7 @@ class FileUploadParser(BaseParser):
if 'filename*' in filename_parm:
return self.get_encoded_filename(filename_parm)
return force_text(filename_parm['filename'])
except (AttributeError, KeyError):
except (AttributeError, KeyError, ValueError):
pass
def get_encoded_filename(self, filename_parm):

View File

@ -161,7 +161,9 @@ class TestFileUploadParser(TestCase):
self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt')
filename = parser.get_filename(self.stream, None, self.parser_context)
self.assertEqual(filename, 'fallback.txt')
# Malformed. Either None or 'fallback.txt' will be acceptable.
# See also https://code.djangoproject.com/ticket/24209
self.assertIn(filename, ('fallback.txt', None))
def __replace_content_disposition(self, disposition):
self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = disposition