Fix HeaderSegmentCollection failing when header value has a trailing space (#23159)

Co-authored-by: Filip Staffa <git@filipstaffa.net>
This commit is contained in:
Filip Staffa 2020-07-01 00:05:54 +02:00 committed by GitHub
parent 71e388eab7
commit e1d4728d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -254,6 +254,11 @@ namespace Microsoft.AspNetCore.Http
switch (attr)
{
case Attr.Delimiter:
if (ch == (char)0)
{
_valueEnd = _offset;
_trailingStart = _offset;
}
_mode = Mode.Produce;
break;
case Attr.Quote:

View File

@ -103,5 +103,18 @@ namespace Microsoft.AspNetCore.Http
Assert.Throws<InvalidOperationException>(() => headers.Remove(new KeyValuePair<string, StringValues>("header1", "value1")));
Assert.Throws<InvalidOperationException>(() => headers.Remove("header1"));
}
[Fact]
public void GetCommaSeparatedValues_WorksForUnquotedHeaderValuesEndingWithSpace()
{
var headers = new HeaderDictionary
{
{ "Via", "value " },
};
var result = headers.GetCommaSeparatedValues("Via");
Assert.Equal(new[]{"value "}, result);
}
}
}
}