diff options
| author | Tom Christie | 2015-01-23 12:26:44 +0000 | 
|---|---|---|
| committer | Tom Christie | 2015-01-23 12:26:44 +0000 | 
| commit | f1ac9d3f9b6c306b7fa48381006d8259c1642a99 (patch) | |
| tree | 1f0c3d76a16b8bf0711d79f7f8da5af046f9e639 | |
| parent | 4cb164b66c0784ce79054925d4744deb5b18d8b2 (diff) | |
| download | django-rest-framework-f1ac9d3f9b6c306b7fa48381006d8259c1642a99.tar.bz2 | |
More graceful handling of malformed Content-Disposition
| -rw-r--r-- | rest_framework/parsers.py | 2 | ||||
| -rw-r--r-- | tests/test_parsers.py | 4 | 
2 files changed, 4 insertions, 2 deletions
| diff --git a/rest_framework/parsers.py b/rest_framework/parsers.py index 401856ec..ef72677c 100644 --- a/rest_framework/parsers.py +++ b/rest_framework/parsers.py @@ -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): diff --git a/tests/test_parsers.py b/tests/test_parsers.py index d28d8bd4..1d2054ac 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -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 | 
