Add null-check back to MediaType
This commit is contained in:
parent
6f7fc4fb34
commit
6396e14504
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue