Fix for Issue#5150

This commit is contained in:
joheredi 2016-08-18 15:04:14 -07:00 committed by jacalvar
parent 61de7fec6f
commit 38aa48651f
2 changed files with 17 additions and 1 deletions

View File

@ -308,7 +308,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
// We check if the parsed media type has value at this stage when we have iterated
// over all the parameters and we know if the parsing was sucessful.
if (!parser.ParsingFailed)
if (!parser.ParsingFailed && parser.CurrentOffset >= start)
{
return new MediaTypeSegmentWithQuality(
new StringSegment(mediaType, start, parser.CurrentOffset - start),

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Primitives;
using Xunit;
@ -48,6 +49,21 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Internal
}
}
[Fact]
public void ParseAcceptHeader_ParsesSimpleHeaderWithMultipleValues_InvalidFormat()
{
// Arrange
var header = "application/json, application/xml,;q=0.8";
var expectedException = "\"Invalid values ';q=0.8'.\"";
// Act
var ex = Assert.Throws<FormatException>(
() => { AcceptHeaderParser.ParseAcceptHeader(new List<string> { header }); });
// Assert
Assert.Equal(expectedException, ex.Message);
}
[Fact]
public void ParseAcceptHeader_ParsesMultipleHeaderValues()
{