diff options
| author | Mehrdad <mhrddmoradii@gmail.com> | 2022-06-24 14:46:34 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-06-28 09:42:47 +0200 |
| commit | d4d5427571b4bf3a21c902276c2a00215c2a37cc (patch) | |
| tree | 59cc1bc214b414636b57b0e61fc6515a6e528f5f /django/utils/http.py | |
| parent | bff5c114be2b7a3fbc735c232abcc6ad4db89a9d (diff) | |
Refs #33697 -- Used django.utils.http.parse_header_parameters() for parsing boundary streams.
This also removes unused parse_header() and _parse_header_params()
helpers in django.http.multipartparser.
Diffstat (limited to 'django/utils/http.py')
| -rw-r--r-- | django/utils/http.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index 6e2091bf52..51fdc4b149 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -11,6 +11,7 @@ from urllib.parse import ( _splitnetloc, _splitparams, scheme_chars, + unquote, ) from urllib.parse import urlencode as original_urlencode from urllib.parse import uses_params @@ -387,15 +388,25 @@ def parse_header_parameters(line): Return the main content-type and a dictionary of options. """ parts = _parseparam(";" + line) - key = parts.__next__() + key = parts.__next__().lower() pdict = {} for p in parts: i = p.find("=") if i >= 0: + has_encoding = False name = p[:i].strip().lower() + if name.endswith("*"): + # Lang/encoding embedded in the value (like "filename*=UTF-8''file.ext") + # https://tools.ietf.org/html/rfc2231#section-4 + name = name[:-1] + if p.count("'") == 2: + has_encoding = True value = p[i + 1 :].strip() if len(value) >= 2 and value[0] == value[-1] == '"': value = value[1:-1] value = value.replace("\\\\", "\\").replace('\\"', '"') + if has_encoding: + encoding, lang, value = value.split("'") + value = unquote(value, encoding=encoding) pdict[name] = value return key, pdict |
