diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-07-12 14:08:50 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-08-14 11:45:43 +0200 |
| commit | b42e5ca058178d67027bf66d37d00ade635b4c26 (patch) | |
| tree | bfe9c7ef7689b2f462c6a50f4eea35b05490476a /django/http/multipartparser.py | |
| parent | 7244a8d0ae296833201e634ac31177b936da2ad9 (diff) | |
Fixed #22971 -- Properly parsed RFC 2388 encoded headers
Thanks homm for the report, Cea Stapleton for patch improvements
and Ian Cordasco, Christian Schmitt and Tim Graham for the review.
Diffstat (limited to 'django/http/multipartparser.py')
| -rw-r--r-- | django/http/multipartparser.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py index 1bcace94cd..fd9f3a5b32 100644 --- a/django/http/multipartparser.py +++ b/django/http/multipartparser.py @@ -16,6 +16,7 @@ from django.core.exceptions import SuspiciousMultipartForm from django.utils.datastructures import MultiValueDict from django.utils.encoding import force_text from django.utils import six +from django.utils.six.moves.urllib.parse import unquote from django.utils.text import unescape_entities from django.core.files.uploadhandler import StopUpload, SkipFile, StopFutureHandlers @@ -631,8 +632,20 @@ def parse_header(line): for p in plist: i = p.find(b'=') if i >= 0: + has_encoding = False name = p[:i].strip().lower().decode('ascii') + if name.endswith('*'): + # Lang/encoding embedded in the value (like "filename*=UTF-8''file.ext") + # http://tools.ietf.org/html/rfc2231#section-4 + name = name[:-1] + has_encoding = True value = p[i + 1:].strip() + if has_encoding: + encoding, lang, value = value.split(b"'") + if six.PY3: + value = unquote(value.decode(), encoding=encoding.decode()) + else: + value = unquote(value).decode(encoding) if len(value) >= 2 and value[:1] == value[-1:] == b'"': value = value[1:-1] value = value.replace(b'\\\\', b'\\').replace(b'\\"', b'"') |
