Add null-check back to MediaType
This commit is contained in:
parent
6f7fc4fb34
commit
6396e14504
|
|
@ -55,14 +55,17 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
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)
|
if (offset > mediaType.Length - length)
|
||||||
{
|
{
|
||||||
throw new ArgumentException(Resources.FormatArgument_InvalidOffsetLength(nameof(offset), nameof(length)));
|
throw new ArgumentException(Resources.FormatArgument_InvalidOffsetLength(nameof(offset), nameof(length)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_parameterParser = default(MediaTypeParameterParser);
|
_parameterParser = default(MediaTypeParameterParser);
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,16 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
Assert.Equal(new StringSegment("utf-8"), result.GetParameter("charset"));
|
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]
|
[Fact]
|
||||||
public void Constructor_NullMediaType_Throws()
|
public void Constructor_NullMediaType_Throws()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue