Fix encoded filename parsing to allow for lang

This commit is contained in:
Jason Bittel 2014-09-05 15:22:43 -07:00
parent bcd8a24db1
commit c8e475023c
2 changed files with 5 additions and 1 deletions

View File

@ -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'])

View File

@ -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')