SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
fix: normalize Content-Type parameters in multimodal image processing (#1446)
Anas Khan10ab1a978954
diff --git a/sweagent/agent/problem_statement.py b/sweagent/agent/problem_statement.pyindex 582f4520..881d54bc 100644--- a/sweagent/agent/problem_statement.py+++ b/sweagent/agent/problem_statement.py@@ -237,7 +237,8 @@ class SWEBenchMultimodalProblemStatement(_BuiltinProblemStatementBase):}response = requests.get(url, headers=headers, timeout=30, stream=True)response.raise_for_status()- content_type = response.headers.get("content-type", "").lower()+ # strip any media type parameters (e.g. "image/png; charset=utf-8") before validation+ content_type = response.headers.get("content-type", "").split(";")[0].strip().lower()if content_type == "image/jpg":content_type = "image/jpeg"if content_type not in VALID_IMAGE_MIME_TYPES:diff --git a/tests/test_problem_statement_multimodal.py b/tests/test_problem_statement_multimodal.pyindex 76043042..635685e9 100644--- a/tests/test_problem_statement_multimodal.py+++ b/tests/test_problem_statement_multimodal.py@@ -43,6 +43,23 @@ class TestSWEBenchMultimodalProblemStatement:assert "Test problem statement" in resultassert f"+ def test_get_problem_statement_with_content_type_parameters(self, mock_get):+ """Test that a Content-Type header with media type parameters is still accepted."""+ # servers may append parameters like charset, which is legal per RFC 9110+ mock_response = Mock()+ mock_response.raise_for_status.return_value = None+ mock_response.headers = {"content-type": "image/png; charset=utf-8"}+ mock_response.iter_content.return_value = [b"fake_image_data"]+ mock_get.return_value = mock_response+ problem_statement = SWEBenchMultimodalProblemStatement(+ text="Test problem statement", issue_images=[self.example_image_url]+ )+ result = problem_statement.get_problem_statement()+ # the parameters should be stripped before validation and encoding+ assert "Test problem statement" in result+ assert f"def test_get_problem_statement_with_network_error(self, mock_get):"""Test that network errors are handled gracefully with warnings."""