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

Fix for https://github.com/aspnet/Mvc/issues/4883 #658

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public bool MoveNext()
switch (attr)
{
case Attr.Delimiter:
_valueStart = _valueStart == -1 ? _offset : _valueStart;
_valueEnd = _valueEnd == -1 ? _offset : _valueEnd;
_trailingStart = _trailingStart == -1 ? _offset : _trailingStart;
_leadingEnd = _offset;
_mode = Mode.Produce;
break;
Expand Down
28 changes: 28 additions & 0 deletions test/Microsoft.AspNetCore.Http.Tests/HeaderDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,33 @@ public void PropertiesAreAccessible()
Assert.Equal("Value1", headers["header1"]);
Assert.Equal(new[] { "Value1" }, headers["header1"].ToArray());
}

[Fact]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this test be written as a Theory?

public void EmptyHeaderSegmentsAreParsable()
{
var values1 = new[] { "Value1", "Value2", "Value3", "Value4" };
var values2 = new[] { "Value1", "", "Value3", "Value4" };
var values3 = new[] { "Value1", "", "", "Value4" };
var values4 = new[] { "", "", "", "" };

var headers = new HeaderDictionary(
new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase)
{
{ "Header1", string.Join(",", values1) },
{ "Header2", string.Join(",", values2) },
{ "Header3", string.Join(",", values3) },
{ "Header4", string.Join(",", values4) },
});

var comma1 = headers.GetCommaSeparatedValues("Header1");
var comma2 = headers.GetCommaSeparatedValues("Header2");
var comma3 = headers.GetCommaSeparatedValues("Header3");
var comma4 = headers.GetCommaSeparatedValues("Header4");

Assert.Equal(values1, comma1);
Assert.Equal(values2, comma2);
Assert.Equal(values3, comma3);
Assert.Equal(values4, comma4);
}
}
}