Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Microsoft.Net.Http.Headers/MediaTypeHeaderValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ private bool MatchesSubtype(MediaTypeHeaderValue set)
{
return true;
}

if (set.Suffix.HasValue)
{
if (Suffix.HasValue)
Expand All @@ -663,7 +664,10 @@ private bool MatchesSubtype(MediaTypeHeaderValue set)
}
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);
}
}

Expand All @@ -673,6 +677,12 @@ private bool MatchesSubtypeWithoutSuffix(MediaTypeHeaderValue set)
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)
{
if (set._parameters != null && set._parameters.Count != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ public void IsSubsetOf_NegativeCases(string mediaType1, string mediaType2)
[InlineData("application/entity+json", "application/entity+json")]
[InlineData("application/*+json", "application/entity+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/vnd.github+json", "application/vnd.github+json")]
[InlineData("application/*", "application/entity+JSON")]
Expand All @@ -774,6 +776,7 @@ public void IsSubsetOfWithSuffixes_PositiveCases(string set, string subset)
[InlineData("application/*+*", "application/json")]
[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/entity+json", "application/entity")]
public void IsSubSetOfWithSuffixes_NegativeCases(string set, string subset)
{
// Arrange
Expand Down