diff --git a/src/cloudevents/core/formats/json.py b/src/cloudevents/core/formats/json.py index fa99cfee..777377ce 100644 --- a/src/cloudevents/core/formats/json.py +++ b/src/cloudevents/core/formats/json.py @@ -46,7 +46,8 @@ class JSONFormat(Format): CONTENT_TYPE: Final[str] = "application/cloudevents+json" DEFAULT_CONTENT_TYPE: Final[str] = "application/json" JSON_CONTENT_TYPE_PATTERN: Pattern[str] = re.compile( - r"^(application|text)/([a-zA-Z0-9\-\.]+\+)?json(;.*)?$" + r"^(application|text)/([a-zA-Z0-9\-\.]+\+)?json(;.*)?$", + re.IGNORECASE | re.ASCII, ) def read( diff --git a/tests/test_core/test_format/test_json.py b/tests/test_core/test_format/test_json.py index 91abbdc0..d8554b1f 100644 --- a/tests/test_core/test_format/test_json.py +++ b/tests/test_core/test_format/test_json.py @@ -252,6 +252,7 @@ def test_write_cloud_event_with_different_json_content_types() -> None: ("application/vnd.api+json", {"key": "value"}), ("text/json", {"key": "value"}), ("application/json; charset=utf-8", {"key": "value"}), + ("Application/vnd.api+JSON; profile=Example", {"key": "value"}), ] for content_type, data in test_cases: @@ -264,9 +265,10 @@ def test_write_cloud_event_with_different_json_content_types() -> None: } event = CloudEvent(attributes=attributes, data=data) formatter = JSONFormat() - result = formatter.write(event) + result = loads(formatter.write(event)) - assert b'"data": {"key": "value"}' in result + assert result["data"] == data + assert result["datacontenttype"] == content_type def test_read_cloud_event_with_string_data() -> None: @@ -341,7 +343,7 @@ def test_write_data_dict(content_type: str) -> None: assert loads(result) == data -@pytest.mark.parametrize("content_type", [None, "application/json"]) +@pytest.mark.parametrize("content_type", [None, "application/json", "Application/JSON"]) def test_read_data_json_body(content_type: str) -> None: formatter = JSONFormat() body = b'{"key": "value"}'