Handle subtype with suffix being a subtype without a suffix (#8170)
This commit is contained in:
parent
0102d4efab
commit
367717760b
|
|
@ -488,9 +488,10 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The set has no suffix, so we're just looking for an exact match (which means that if 'this'
|
// If this subtype or suffix matches the subtype of the set,
|
||||||
// has a suffix, it won't match).
|
// it is considered a subtype.
|
||||||
return set.SubType.Equals(SubType, StringComparison.OrdinalIgnoreCase);
|
// Ex: application/json > application/val+json
|
||||||
|
return MatchesEitherSubtypeOrSuffix(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -507,6 +508,12 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
return set.SubTypeSuffix.Equals(SubTypeSuffix, StringComparison.OrdinalIgnoreCase);
|
return set.SubTypeSuffix.Equals(SubTypeSuffix, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool MatchesEitherSubtypeOrSuffix(MediaType set)
|
||||||
|
{
|
||||||
|
return set.SubType.Equals(SubType, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
set.SubType.Equals(SubTypeSuffix, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
private bool ContainsAllParameters(MediaTypeParameterParser setParameters)
|
private bool ContainsAllParameters(MediaTypeParameterParser setParameters)
|
||||||
{
|
{
|
||||||
var parameterFound = true;
|
var parameterFound = true;
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,9 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("application/xml")]
|
[InlineData("application/xml")]
|
||||||
|
[InlineData("application/mathml-content+xml")]
|
||||||
|
[InlineData("application/mathml-presentation+xml")]
|
||||||
|
[InlineData("application/mathml+xml; test=value")]
|
||||||
public void XMLFormatter_CanRead_ReturnsTrueForSupportedMediaTypes(string requestContentType)
|
public void XMLFormatter_CanRead_ReturnsTrueForSupportedMediaTypes(string requestContentType)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -289,9 +292,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("application/mathml-content+xml")]
|
|
||||||
[InlineData("application/mathml-presentation+xml")]
|
|
||||||
[InlineData("application/mathml+xml; undefined=ignored")]
|
|
||||||
[InlineData("application/octet-stream; padding=3")]
|
[InlineData("application/octet-stream; padding=3")]
|
||||||
[InlineData("application/xml-dtd; undefined=ignored")]
|
[InlineData("application/xml-dtd; undefined=ignored")]
|
||||||
[InlineData("multipart/mixed; boundary=gc0p4Jq0M2Yt08j34c0p")]
|
[InlineData("multipart/mixed; boundary=gc0p4Jq0M2Yt08j34c0p")]
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
[InlineData("application/entity+json", "application/entity+json")]
|
[InlineData("application/entity+json", "application/entity+json")]
|
||||||
[InlineData("application/*+json", "application/entity+json")]
|
[InlineData("application/*+json", "application/entity+json")]
|
||||||
[InlineData("application/*", "application/entity+json")]
|
[InlineData("application/*", "application/entity+json")]
|
||||||
|
[InlineData("application/json", "application/vnd.restful+json")]
|
||||||
|
[InlineData("application/json", "application/problem+json")]
|
||||||
public void IsSubsetOf_ReturnsTrueWhenExpected(string set, string subset)
|
public void IsSubsetOf_ReturnsTrueWhenExpected(string set, string subset)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -242,6 +244,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
[InlineData("application/*+*", "application/json")]
|
[InlineData("application/*+*", "application/json")]
|
||||||
[InlineData("application/entity+*", "application/entity+json")] // We don't allow suffixes to be wildcards
|
[InlineData("application/entity+*", "application/entity+json")] // We don't allow suffixes to be wildcards
|
||||||
[InlineData("application/*+*", "application/entity+json")] // We don't allow suffixes to be wildcards
|
[InlineData("application/*+*", "application/entity+json")] // We don't allow suffixes to be wildcards
|
||||||
|
[InlineData("application/entity+json", "application/entity")]
|
||||||
public void IsSubsetOf_ReturnsFalseWhenExpected(string set, string subset)
|
public void IsSubsetOf_ReturnsFalseWhenExpected(string set, string subset)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
[InlineData("application/some.entity+json;v=2", true)]
|
[InlineData("application/some.entity+json;v=2", true)]
|
||||||
[InlineData("application/some.entity+xml", false)]
|
[InlineData("application/some.entity+xml", false)]
|
||||||
[InlineData("application/some.entity+*", false)]
|
[InlineData("application/some.entity+*", false)]
|
||||||
[InlineData("text/some.entity+json", false)]
|
[InlineData("text/some.entity+json", true)]
|
||||||
[InlineData("", false)]
|
[InlineData("", false)]
|
||||||
[InlineData(null, false)]
|
[InlineData(null, false)]
|
||||||
[InlineData("invalid", false)]
|
[InlineData("invalid", false)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue