Skip to content

Commit

Permalink
- fixes #3667 a bug where missing mime type parameters would lead to …
Browse files Browse the repository at this point in the history
…no matches
  • Loading branch information
baywet committed Nov 7, 2023
1 parent c6f73b9 commit 62c41c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ private bool TryGetMimeType(string mimeType, out float result)
return false;
}

return _mimeTypes.TryGetValue(mimeType, out result) ||
return _mimeTypes.TryGetValue(mimeType, out result) || // vendor and parameters
mimeType.Contains('+', StringComparison.OrdinalIgnoreCase) &&
_mimeTypes.TryGetValue(vendorStripRegexInstance.Replace(mimeType, string.Empty), out result);
_mimeTypes.TryGetValue(vendorStripRegexInstance.Replace(mimeType, string.Empty), out result) || // no vendor with parameters
mimeType.Contains(';', StringComparison.OrdinalIgnoreCase) &&
mimeType.Split(';', StringSplitOptions.RemoveEmptyEntries)[0] is string noParametersMimeType &&
(_mimeTypes.TryGetValue(noParametersMimeType, out result) || // vendor without parameters
_mimeTypes.TryGetValue(vendorStripRegexInstance.Replace(noParametersMimeType, string.Empty), out result)); // no vendor without parameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void ClearsEntries()
[InlineData("application/json, application/xml, application/yaml;q=0.8", "application/json,text/plain,application/yaml", "application/json;q=1,application/yaml;q=0.8")]
[InlineData("application/json, application/xml;q=0.9, application/yaml;q=0.8", "application/github+json", "application/github+json;q=1")]
[InlineData("application/vnd.topicus.keyhub+json;version=67, application/yaml;q=0.8", "application/vnd.topicus.keyhub+json;version=67", "application/vnd.topicus.keyhub+json;version=67;q=1")]
[InlineData("application/vnd.topicus.keyhub+json, application/yaml;q=0.8", "application/vnd.topicus.keyhub+json;version=67", "application/vnd.topicus.keyhub+json;version=67;q=1")]
public void MatchesAccept(string configuredTypes, string declaredTypes, string expectedTypes)
{
var mimeTypes = new StructuredMimeTypesCollection(configuredTypes.Split(',').Select(static x => x.Trim()));
Expand Down

0 comments on commit 62c41c5

Please sign in to comment.