mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
More graceful handling of malformed Content-Disposition
This commit is contained in:
parent
4cb164b66c
commit
f1ac9d3f9b
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user