Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cloudevents/core/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions tests/test_core/test_format/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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"}'
Expand Down