mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Fix encoded filename parsing to allow for lang
This commit is contained in:
parent
bcd8a24db1
commit
c8e475023c
|
@ -303,7 +303,7 @@ class FileUploadParser(BaseParser):
|
||||||
"""
|
"""
|
||||||
encoded_filename = force_text(disposition['filename*'])
|
encoded_filename = force_text(disposition['filename*'])
|
||||||
try:
|
try:
|
||||||
charset, filename = encoded_filename.split('\'\'', 1)
|
charset, lang, filename = encoded_filename.split('\'', 2)
|
||||||
filename = urlparse.unquote(filename)
|
filename = urlparse.unquote(filename)
|
||||||
except (ValueError, LookupError):
|
except (ValueError, LookupError):
|
||||||
filename = force_text(disposition['filename'])
|
filename = force_text(disposition['filename'])
|
||||||
|
|
|
@ -127,6 +127,10 @@ class TestFileUploadParser(TestCase):
|
||||||
filename = parser.get_filename(self.stream, None, self.parser_context)
|
filename = parser.get_filename(self.stream, None, self.parser_context)
|
||||||
self.assertEqual(filename, 'ÀĥƦ.txt')
|
self.assertEqual(filename, 'ÀĥƦ.txt')
|
||||||
|
|
||||||
|
self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'en-us\'ÀĥƦ.txt')
|
||||||
|
filename = parser.get_filename(self.stream, None, self.parser_context)
|
||||||
|
self.assertEqual(filename, 'ÀĥƦ.txt')
|
||||||
|
|
||||||
self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt')
|
self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt')
|
||||||
filename = parser.get_filename(self.stream, None, self.parser_context)
|
filename = parser.get_filename(self.stream, None, self.parser_context)
|
||||||
self.assertEqual(filename, 'fallback.txt')
|
self.assertEqual(filename, 'fallback.txt')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user