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/http | |
| 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/http')
| -rw-r--r-- | django/http/multipartparser.py | 51 |
1 files changed, 2 insertions, 49 deletions
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py index 73ef074744..b3e0925a42 100644 --- a/django/http/multipartparser.py +++ b/django/http/multipartparser.py @@ -8,7 +8,6 @@ import base64 import binascii import collections import html -from urllib.parse import unquote from django.conf import settings from django.core.exceptions import ( @@ -675,8 +674,9 @@ def parse_boundary_stream(stream, max_header_size): # This terminology ("main value" and "dictionary of # parameters") is from the Python docs. try: - main_value_pair, params = parse_header(line) + main_value_pair, params = parse_header_parameters(line.decode()) name, value = main_value_pair.split(":", 1) + params = {k: v.encode() for k, v in params.items()} except ValueError: # Invalid header. continue @@ -703,50 +703,3 @@ class Parser: for sub_stream in boundarystream: # Iterate over each part yield parse_boundary_stream(sub_stream, 1024) - - -def parse_header(line): - """ - Parse the header into a key-value. - - Input (line): bytes, output: str for key/name, bytes for values which - will be decoded later. - """ - plist = _parse_header_params(b";" + line) - key = plist.pop(0).lower().decode("ascii") - pdict = {} - 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") - # https://tools.ietf.org/html/rfc2231#section-4 - name = name[:-1] - if p.count(b"'") == 2: - has_encoding = True - value = p[i + 1 :].strip() - if len(value) >= 2 and value[:1] == value[-1:] == b'"': - value = value[1:-1] - value = value.replace(b"\\\\", b"\\").replace(b'\\"', b'"') - if has_encoding: - encoding, lang, value = value.split(b"'") - value = unquote(value.decode(), encoding=encoding.decode()) - pdict[name] = value - return key, pdict - - -def _parse_header_params(s): - plist = [] - while s[:1] == b";": - s = s[1:] - end = s.find(b";") - while end > 0 and (s.count(b'"', 0, end) - s.count(b'\\"', 0, end)) % 2: - end = s.find(b";", end + 1) - if end < 0: - end = len(s) - f = s[:end] - plist.append(f.strip()) - s = s[end:] - return plist |
