From e1d4728d904e5e0768872713cbcdfa0483843922 Mon Sep 17 00:00:00 2001 From: Filip Staffa Date: Wed, 1 Jul 2020 00:05:54 +0200 Subject: [PATCH] Fix HeaderSegmentCollection failing when header value has a trailing space (#23159) Co-authored-by: Filip Staffa --- .../src/Internal/HeaderSegmentCollection.cs | 5 +++++ src/Http/Http/test/HeaderDictionaryTests.cs | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs b/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs index b83bf4eeea..e06ae7b012 100644 --- a/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs +++ b/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs @@ -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: diff --git a/src/Http/Http/test/HeaderDictionaryTests.cs b/src/Http/Http/test/HeaderDictionaryTests.cs index 26113f53c0..e9cf32ebe3 100644 --- a/src/Http/Http/test/HeaderDictionaryTests.cs +++ b/src/Http/Http/test/HeaderDictionaryTests.cs @@ -103,5 +103,18 @@ namespace Microsoft.AspNetCore.Http Assert.Throws(() => headers.Remove(new KeyValuePair("header1", "value1"))); Assert.Throws(() => headers.Remove("header1")); } + + [Fact] + public void GetCommaSeparatedValues_WorksForUnquotedHeaderValuesEndingWithSpace() + { + var headers = new HeaderDictionary + { + { "Via", "value " }, + }; + + var result = headers.GetCommaSeparatedValues("Via"); + + Assert.Equal(new[]{"value "}, result); + } } -} \ No newline at end of file +}