diff --git a/src/shared/Core.Tests/StreamExtensionsTests.cs b/src/shared/Core.Tests/StreamExtensionsTests.cs index 3a3f203f1..56a7c762b 100644 --- a/src/shared/Core.Tests/StreamExtensionsTests.cs +++ b/src/shared/Core.Tests/StreamExtensionsTests.cs @@ -254,6 +254,19 @@ public void StreamExtensions_ReadMultiDictionary_CaseInsensitive_ReturnsDictiona AssertMultiDictionary(new[] { "2" }, "a", output); } + [Fact] + public void StreamExtensions_ReadMultiDictionary_EmptyString_ReturnsKeyWithEmptyStringValue() + { + string input = "a=\n\n"; + + var output = ReadStringStream(input, StreamExtensions.ReadMultiDictionary); + + Assert.NotNull(output); + Assert.Equal(1, output.Count); + + AssertMultiDictionary(new[] { String.Empty, }, "a", output); + } + [Fact] public void StreamExtensions_ReadMultiDictionary_Spaces_ReturnsCorrectKeysAndValues() { diff --git a/src/shared/Core/StreamExtensions.cs b/src/shared/Core/StreamExtensions.cs index bbf2a359b..7ff338f5a 100644 --- a/src/shared/Core/StreamExtensions.cs +++ b/src/shared/Core/StreamExtensions.cs @@ -248,14 +248,15 @@ private static void ParseMultiLine(IDictionary> dict, stri // Only allow one value for non-multi/array entries ("key=value") // and reset the array of a multi-entry if the value is empty ("key[]=") bool emptyValue = string.IsNullOrEmpty(value); + if (!multi || emptyValue) { list.Clear(); + } - if (emptyValue) - { - return; - } + if (multi && emptyValue) + { + return; } list.Add(value);