resolved RESOLVED UNSUBMITTED PASS · None tool calls · 0 s · psf/requests
Fix malformed value parsing for Content-Type This PR addresses https://github.com/psf/requests/issues/6646 by cleaning up `_parse_content_type_header`. Instead of setting a default that we can't use in practice, we now skip value assignment completely if the value is malformed. Every RFC from 1521 to 9110 is clear that an `=` is required for a valid parameter. If it doesn't exist, we need to ignore it.
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
--- a/src/requests/utils.py
+++ b/src/requests/utils.py
@@ -502,26 +502,23 @@ def get_encodings_from_content(content):
def _parse_content_type_header(header):
- """Returns content type and parameters from given header
+ """Returns content type and parameters from given header.
:param header: string
:return: tuple containing content type and dictionary of
- parameters
+ parameters.
"""
tokens = header.split(";")
content_type, params = tokens[0].strip(), tokens[1:]
params_dict = {}
- items_to_strip = "\"' "
+ strip_chars = "\"' "
for param in params:
param = param.strip()
- if param:
- key, value = param, True
- index_of_equals = param.find("=")
- if index_of_equals != -1:
- key = param[:index_of_equals].strip(items_to_strip)
- value = param[index_of_equals + 1 :].strip(items_to_strip)
+ if param and (idx := param.find("=")) != -1:
+ key = param[:idx].strip(strip_chars)
+ value = param[idx + 1 :].strip(strip_chars)
params_dict[key.lower()] = value
return content_type, params_dict
..s..................................................................... [ 32%]
........................................................................ [ 65%]
...........................................................sssssssssss.. [ 98%]
...s [100%]
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/requests/lib/python3.13/site-packages/_pytest/config/__init__.py:1464
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/requests/lib/python3.13/site-packages/_pytest/config/__init__.py:1464: PytestConfigWarning: Unknown config option: timeout
self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")
tests/test_utils.py::TestContentEncodingDetection::test_none
tests/test_utils.py::TestContentEncodingDetection::test_pragmas[<meta charset="UTF-8">]
tests/test_utils.py::TestContentEncodingDetection::test_pragmas[<meta http-equiv="Content-type" content="text/html;charset=UTF-8">]
tests/test_utils.py::TestContentEncodingDetection::test_pragmas[<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />]
tests/test_utils.py::TestContentEncodingDetection::test_pragmas[<?xml version="1.0" encoding="UTF-8"?>]
tests/test_utils.py::TestContentEncodingDetection::test_precedence
/tmp/swe_work/oracle_full/requests_7309/b/workspace/src/requests/utils.py:484: DeprecationWarning: In requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)
warnings.warn(
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
207 passed, 13 skipped, 7 warnings in 0.22s
[2026-09-23 18:20:45,858] WARNING in core: flasgger is not installed; serving the static landing page at / and skipping the Swagger UI and /spec.json.