Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 80b6ae4

Browse files
authored
Handle subtype with suffix being a subtype without a suffix (#1027)
1 parent f5adc2b commit 80b6ae4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Microsoft.Net.Http.Headers/MediaTypeHeaderValue.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ private bool MatchesSubtype(MediaTypeHeaderValue set)
650650
{
651651
return true;
652652
}
653+
653654
if (set.Suffix.HasValue)
654655
{
655656
if (Suffix.HasValue)
@@ -663,7 +664,10 @@ private bool MatchesSubtype(MediaTypeHeaderValue set)
663664
}
664665
else
665666
{
666-
return set.SubType.Equals(SubType, StringComparison.OrdinalIgnoreCase);
667+
// If this subtype or suffix matches the subtype of the set,
668+
// it is considered a subtype.
669+
// Ex: application/json > application/val+json
670+
return MatchesEitherSubtypeOrSuffix(set);
667671
}
668672
}
669673

@@ -673,6 +677,12 @@ private bool MatchesSubtypeWithoutSuffix(MediaTypeHeaderValue set)
673677
set.SubTypeWithoutSuffix.Equals(SubTypeWithoutSuffix, StringComparison.OrdinalIgnoreCase);
674678
}
675679

680+
private bool MatchesEitherSubtypeOrSuffix(MediaTypeHeaderValue set)
681+
{
682+
return set.SubType.Equals(SubType, StringComparison.OrdinalIgnoreCase) ||
683+
set.SubType.Equals(Suffix, StringComparison.OrdinalIgnoreCase);
684+
}
685+
676686
private bool MatchesParameters(MediaTypeHeaderValue set)
677687
{
678688
if (set._parameters != null && set._parameters.Count != 0)

test/Microsoft.Net.Http.Headers.Tests/MediaTypeHeaderValueTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ public void IsSubsetOf_NegativeCases(string mediaType1, string mediaType2)
750750
[InlineData("application/entity+json", "application/entity+json")]
751751
[InlineData("application/*+json", "application/entity+json")]
752752
[InlineData("application/*+json", "application/*+json")]
753+
[InlineData("application/json", "application/problem+json")]
754+
[InlineData("application/json", "application/vnd.restful+json")]
753755
[InlineData("application/*", "application/*+JSON")]
754756
[InlineData("application/vnd.github+json", "application/vnd.github+json")]
755757
[InlineData("application/*", "application/entity+JSON")]
@@ -774,6 +776,7 @@ public void IsSubsetOfWithSuffixes_PositiveCases(string set, string subset)
774776
[InlineData("application/*+*", "application/json")]
775777
[InlineData("application/entity+*", "application/entity+json")] // We don't allow suffixes to be wildcards
776778
[InlineData("application/*+*", "application/entity+json")] // We don't allow suffixes to be wildcards
779+
[InlineData("application/entity+json", "application/entity")]
777780
public void IsSubSetOfWithSuffixes_NegativeCases(string set, string subset)
778781
{
779782
// Arrange

0 commit comments

Comments
 (0)