Skip to content

fix: accept media types with parameters in datacontenttype - #66

Merged
duglin merged 1 commit into
cloudevents:mainfrom
EmiRZx:fix-datacontenttype-media-type
Dec 3, 2026
Merged

duglin merged 1 commit into
cloudevents:mainfrom
EmiRZx:fix-datacontenttype-media-type

Conversation

@EmiRZx

@EmiRZx EmiRZx commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

fixes #65. the type and subtype are now RFC 9110 tokens. parameters are allowed as long as they have no control characters. a trailing newline or a CRLF is rejected. new tests cover valid and invalid values and a binary request with charset=utf-8. they fail on main and pass here. tests pass on PHP 7.4 and 8.4. phpcs and psalm are clean.

The check only allowed [-\w] around the slash, so valid types such as
application/json; charset=utf-8 (the HTTP binding's own example),
application/vnd.apache.thrift.binary and image/svg+xml were rejected,
and a binary request with a charset parameter failed to unmarshal. It
also accepted a trailing newline.

The check now uses RFC 9110 tokens for the type and subtype and allows
parameters without control characters.

Signed-off-by: emir <52245396+EmiRZx@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the expanded CloudEvent content-type validation.

No open issues 🎉

What changed in this PR

Fixes #65 by expanding CloudEvent datacontenttype validation to accept media types with parameters, dots, and plus signs while rejecting trailing newlines.

Changes:

  • Uses RFC 9110 tokens for media type and subtype validation.
  • Adds valid and invalid content-type test cases.
  • Tests binary HTTP unmarshalling with charset=utf-8.
File Description
tests/​Unit/​V1/​CloudEventTest.php Adds content-type validation tests.
tests/​Unit/​Http/​UnmarshallerTest.php Tests binary requests with content-type parameters.
src/​V1/​CloudEventTrait.php Expands media-type validation and rejects trailing newlines.

Review effort: Balanced

@duglin
duglin merged commit e7a1176 into cloudevents:main Dec 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datacontenttype rejects media types with parameters, dots or plus signs

3 participants