Handle subtype with suffix being a subtype without a suffix (#1027)

This commit is contained in:
Justin Kotalik 2018-07-30 12:05:35 -07:00 committed by GitHub
parent f5adc2bc31
commit 80b6ae4eb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -650,6 +650,7 @@ namespace Microsoft.Net.Http.Headers
{ {
return true; return true;
} }
if (set.Suffix.HasValue) if (set.Suffix.HasValue)
{ {
if (Suffix.HasValue) if (Suffix.HasValue)
@ -663,7 +664,10 @@ namespace Microsoft.Net.Http.Headers
} }
else else
{ {
return set.SubType.Equals(SubType, StringComparison.OrdinalIgnoreCase); // If this subtype or suffix matches the subtype of the set,
// it is considered a subtype.
// Ex: application/json > application/val+json
return MatchesEitherSubtypeOrSuffix(set);
} }
} }
@ -673,6 +677,12 @@ namespace Microsoft.Net.Http.Headers
set.SubTypeWithoutSuffix.Equals(SubTypeWithoutSuffix, StringComparison.OrdinalIgnoreCase); set.SubTypeWithoutSuffix.Equals(SubTypeWithoutSuffix, StringComparison.OrdinalIgnoreCase);
} }
private bool MatchesEitherSubtypeOrSuffix(MediaTypeHeaderValue set)
{
return set.SubType.Equals(SubType, StringComparison.OrdinalIgnoreCase) ||
set.SubType.Equals(Suffix, StringComparison.OrdinalIgnoreCase);
}
private bool MatchesParameters(MediaTypeHeaderValue set) private bool MatchesParameters(MediaTypeHeaderValue set)
{ {
if (set._parameters != null && set._parameters.Count != 0) if (set._parameters != null && set._parameters.Count != 0)

View File

@ -750,6 +750,8 @@ namespace Microsoft.Net.Http.Headers
[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/*+json", "application/*+json")] [InlineData("application/*+json", "application/*+json")]
[InlineData("application/json", "application/problem+json")]
[InlineData("application/json", "application/vnd.restful+json")]
[InlineData("application/*", "application/*+JSON")] [InlineData("application/*", "application/*+JSON")]
[InlineData("application/vnd.github+json", "application/vnd.github+json")] [InlineData("application/vnd.github+json", "application/vnd.github+json")]
[InlineData("application/*", "application/entity+JSON")] [InlineData("application/*", "application/entity+JSON")]
@ -774,6 +776,7 @@ namespace Microsoft.Net.Http.Headers
[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 IsSubSetOfWithSuffixes_NegativeCases(string set, string subset) public void IsSubSetOfWithSuffixes_NegativeCases(string set, string subset)
{ {
// Arrange // Arrange