Skip to content

Commit f74d383

Browse files
committed
fix: Use just the media type to detect JSON, not whole datacontenttype
Fixes #216 Signed-off-by: Jon Skeet <[email protected]>
1 parent ee9d91a commit f74d383

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

src/CloudNative.CloudEvents.NewtonsoftJson/JsonEventFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ protected virtual void DecodeStructuredModeDataBase64Property(JToken dataBase64T
364364
/// <returns>The data to populate in the <see cref="CloudEvent.Data"/> property.</returns>
365365
protected virtual void DecodeStructuredModeDataProperty(JToken dataToken, CloudEvent cloudEvent)
366366
{
367-
if (IsJsonMediaType(cloudEvent.DataContentType!))
367+
if (IsJsonMediaType(new ContentType(cloudEvent.DataContentType!).MediaType))
368368
{
369369
cloudEvent.Data = dataToken;
370370
}

src/CloudNative.CloudEvents.SystemTextJson/JsonEventFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected virtual void DecodeStructuredModeDataBase64Property(JsonElement dataBa
377377
/// <returns>The data to populate in the <see cref="CloudEvent.Data"/> property.</returns>
378378
protected virtual void DecodeStructuredModeDataProperty(JsonElement dataElement, CloudEvent cloudEvent)
379379
{
380-
if (IsJsonMediaType(cloudEvent.DataContentType!))
380+
if (IsJsonMediaType(new ContentType(cloudEvent.DataContentType!).MediaType))
381381
{
382382
cloudEvent.Data = dataElement.Clone();
383383
}

test/CloudNative.CloudEvents.UnitTests/NewtonsoftJson/JsonEventFormatterTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ public void DecodeStructuredModeMessage_NonJsonContentType_JsonStringToken(strin
767767
[Theory]
768768
[InlineData(null)]
769769
[InlineData("application/json")]
770+
[InlineData("application/json; charset=utf-8")]
770771
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
771772
{
772773
var obj = CreateMinimalValidJObject();
@@ -785,6 +786,7 @@ public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string c
785786
[InlineData(null)]
786787
[InlineData("application/json")]
787788
[InlineData("application/xyz+json")]
789+
[InlineData("application/xyz+json; charset=utf-8")]
788790
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
789791
{
790792
var obj = CreateMinimalValidJObject();

test/CloudNative.CloudEvents.UnitTests/SystemTextJson/JsonEventFormatterTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ public void DecodeStructuredModeMessage_NonJsonContentType_JsonStringToken(strin
787787
[Theory]
788788
[InlineData(null)]
789789
[InlineData("application/json")]
790+
[InlineData("application/json; charset=utf-8")]
790791
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
791792
{
792793
var obj = CreateMinimalValidJObject();
@@ -805,6 +806,7 @@ public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string c
805806
[InlineData(null)]
806807
[InlineData("application/json")]
807808
[InlineData("application/xyz+json")]
809+
[InlineData("application/xyz+json; charset=utf-8")]
808810
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
809811
{
810812
var obj = CreateMinimalValidJObject();

0 commit comments

Comments
 (0)