diff --git a/src/Microsoft.Net.Http.Headers/MediaTypeHeaderValue.cs b/src/Microsoft.Net.Http.Headers/MediaTypeHeaderValue.cs index 32074b44..e0692108 100644 --- a/src/Microsoft.Net.Http.Headers/MediaTypeHeaderValue.cs +++ b/src/Microsoft.Net.Http.Headers/MediaTypeHeaderValue.cs @@ -650,6 +650,7 @@ private bool MatchesSubtype(MediaTypeHeaderValue set) { return true; } + if (set.Suffix.HasValue) { if (Suffix.HasValue) @@ -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); } } @@ -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) diff --git a/test/Microsoft.Net.Http.Headers.Tests/MediaTypeHeaderValueTest.cs b/test/Microsoft.Net.Http.Headers.Tests/MediaTypeHeaderValueTest.cs index 75cccabc..e6c45f35 100644 --- a/test/Microsoft.Net.Http.Headers.Tests/MediaTypeHeaderValueTest.cs +++ b/test/Microsoft.Net.Http.Headers.Tests/MediaTypeHeaderValueTest.cs @@ -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")] @@ -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