Add null-check back to MediaType

This commit is contained in:
Ryan Brandenburg 2017-01-13 16:15:30 -08:00
parent 6f7fc4fb34
commit 6396e14504
2 changed files with 20 additions and 7 deletions

View File

@ -55,16 +55,19 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
throw new ArgumentOutOfRangeException(nameof(offset));
}
if (length < 0 || length > mediaType.Length)
if (length != null)
{
throw new ArgumentOutOfRangeException(nameof(length));
}
if(length < 0 || length > mediaType.Length)
{
throw new ArgumentOutOfRangeException(nameof(length));
}
if (offset > mediaType.Length - length)
{
throw new ArgumentException(Resources.FormatArgument_InvalidOffsetLength(nameof(offset), nameof(length)));
if (offset > mediaType.Length - length)
{
throw new ArgumentException(Resources.FormatArgument_InvalidOffsetLength(nameof(offset), nameof(length)));
}
}
_parameterParser = default(MediaTypeParameterParser);
StringSegment type;

View File

@ -60,6 +60,16 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
Assert.Equal(new StringSegment("utf-8"), result.GetParameter("charset"));
}
[Fact]
public void Constructor_NullLength_IgnoresLength()
{
// Arrange & Act
var result = new MediaType("mediaType", 1, length: null);
// Assert
Assert.Equal(new StringSegment("ediaType"), result.Type);
}
[Fact]
public void Constructor_NullMediaType_Throws()
{