One function

_parse_content_type_header in psf/requests

The author described this change as Fix malformed value parsing for Content-Type (#7309). It counts as a record because the check below fails on the code as it stood at bc7dd0fc4 and passes on f0198e6df, with nothing else changed between the two runs.

Fix saved2026-03-30
Sharing licenceApache-2.0 · LICENSE
Change size+6 9

What the code was meant to do, written into the code itself as a docstring

Returns content type and parameters from given header :param header: string :return: tuple containing content type and dictionary of parameters

The change

11 def _parse_content_type_header(header):
2- """Returns content type and parameters from given header
2+ """Returns content type and parameters from given header.
33
44 :param header: string
55 :return: tuple containing content type and dictionary of
6- parameters
6+ parameters.
77 """
88
99 tokens = header.split(";")
1010 content_type, params = tokens[0].strip(), tokens[1:]
1111 params_dict = {}
12- items_to_strip = "\"' "
12+ strip_chars = "\"' "
1313
1414 for param in params:
1515 param = param.strip()
16- if param:
17- key, value = param, True
18- index_of_equals = param.find("=")
19- if index_of_equals != -1:
20- key = param[:index_of_equals].strip(items_to_strip)
21- value = param[index_of_equals + 1 :].strip(items_to_strip)
16+ if param and (idx := param.find("=")) != -1:
17+ key = param[:idx].strip(strip_chars)
18+ value = param[idx + 1 :].strip(strip_chars)
2219 params_dict[key.lower()] = value
2320 return content_type, params_dict

The check that tells the two apart

failpass·tests/test_utils.py::test__parse_content_type_header[multipart/form-data;

Check file tests/test_utils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itbc7dd0fc4d56e808bcdd85ac2d797b3107c89259
Broken version dated2026-03-30
Modulerequests.utils
Units changed_parse_content_type_header
Fingerprint6e4e66296f7f4e3a
Checked2026-08-17 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in psf/requests