Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 3c0c021

Browse files
committed
#659 Parse headers with consecutive commas
1 parent 20d6081 commit 3c0c021

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Microsoft.AspNetCore.Http.Abstractions/Internal/HeaderSegmentCollection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ public bool MoveNext()
188188
switch (attr)
189189
{
190190
case Attr.Delimiter:
191+
_valueStart = _valueStart == -1 ? _offset : _valueStart;
192+
_valueEnd = _valueEnd == -1 ? _offset : _valueEnd;
193+
_trailingStart = _trailingStart == -1 ? _offset : _trailingStart;
191194
_leadingEnd = _offset;
192195
_mode = Mode.Produce;
193196
break;

test/Microsoft.AspNetCore.Http.Tests/HeaderDictionaryTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ namespace Microsoft.AspNetCore.Http
1010
{
1111
public class HeaderDictionaryTests
1212
{
13+
public static TheoryData HeaderSegmentData => new TheoryData<IEnumerable<string>>
14+
{
15+
new[] { "Value1", "Value2", "Value3", "Value4" },
16+
new[] { "Value1", "", "Value3", "Value4" },
17+
new[] { "Value1", "", "", "Value4" },
18+
new[] { "", "", "", "" }
19+
};
20+
1321
[Fact]
1422
public void PropertiesAreAccessible()
1523
{
@@ -26,5 +34,22 @@ public void PropertiesAreAccessible()
2634
Assert.Equal("Value1", headers["header1"]);
2735
Assert.Equal(new[] { "Value1" }, headers["header1"].ToArray());
2836
}
37+
38+
[Theory]
39+
[MemberData(nameof(HeaderSegmentData))]
40+
public void EmptyHeaderSegmentsAreParsable(IEnumerable<string> segments)
41+
{
42+
var header = string.Join(",", segments);
43+
44+
var headers = new HeaderDictionary(
45+
new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase)
46+
{
47+
{ "Header1", header},
48+
});
49+
50+
var result = headers.GetCommaSeparatedValues("Header1");
51+
52+
Assert.Equal(segments, result);
53+
}
2954
}
3055
}

0 commit comments

Comments
 (0)