Skip to content

Commit

Permalink
fix: Use just the media type to detect JSON, not whole datacontenttype
Browse files Browse the repository at this point in the history
Fixes cloudevents#216

Signed-off-by: Jon Skeet <jonskeet@google.com>
  • Loading branch information
jskeet committed Jun 29, 2022
1 parent ee9d91a commit beaa514
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ protected virtual void DecodeStructuredModeDataBase64Property(JToken dataBase64T
/// <returns>The data to populate in the <see cref="CloudEvent.Data"/> property.</returns>
protected virtual void DecodeStructuredModeDataProperty(JToken dataToken, CloudEvent cloudEvent)
{
if (IsJsonMediaType(cloudEvent.DataContentType!))
if (IsJsonMediaType(new ContentType(cloudEvent.DataContentType!).MediaType))
{
cloudEvent.Data = dataToken;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ protected virtual void DecodeStructuredModeDataBase64Property(JsonElement dataBa
/// <returns>The data to populate in the <see cref="CloudEvent.Data"/> property.</returns>
protected virtual void DecodeStructuredModeDataProperty(JsonElement dataElement, CloudEvent cloudEvent)
{
if (IsJsonMediaType(cloudEvent.DataContentType!))
if (IsJsonMediaType(new ContentType(cloudEvent.DataContentType!).MediaType))
{
cloudEvent.Data = dataElement.Clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ public void DecodeStructuredModeMessage_NonJsonContentType_JsonStringToken(strin
[Theory]
[InlineData(null)]
[InlineData("application/json")]
[InlineData("application/json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
{
var obj = CreateMinimalValidJObject();
Expand All @@ -785,6 +786,7 @@ public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string c
[InlineData(null)]
[InlineData("application/json")]
[InlineData("application/xyz+json")]
[InlineData("application/xyz+json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
{
var obj = CreateMinimalValidJObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ public void DecodeStructuredModeMessage_NonJsonContentType_JsonStringToken(strin
[Theory]
[InlineData(null)]
[InlineData("application/json")]
[InlineData("application/json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
{
var obj = CreateMinimalValidJObject();
Expand All @@ -805,6 +806,7 @@ public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string c
[InlineData(null)]
[InlineData("application/json")]
[InlineData("application/xyz+json")]
[InlineData("application/xyz+json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
{
var obj = CreateMinimalValidJObject();
Expand Down

0 comments on commit beaa514

Please sign in to comment.