From 93cada914ca47632dd6972e6f5d927eebe78ca37 Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Wed, 12 Jul 2023 10:17:41 -0700 Subject: [PATCH] streamext: add empty string in non-multi empty lines Before 2.2.0, we only accepted input arguments in the form key=value. To support the new wwwauth[] argument from Git, we added support for these multi-value args key[]=value. In changing from an dictionary of string:string to string:list we accidentally changed the behaviour of dictionary parsing in the case that an empty valued argument was provided. For example: username=\n Preivously this was returned as an empty string. Post 2.2.0 this became `null`, causing an error in scenarios were before there was none. One such scenario is with Windows Integrated Authentication (for example when connecting to Azure DevOps Server/TFS instances), whereby we return an empty username and password to Git to signal this auth mode. Git then returns to us the empty username and password in a `store` call. Update the handling in `ParseMultiLine` to restore the previous behaviour for empty-valued arguments being mapped to the empty string. --- src/shared/Core.Tests/StreamExtensionsTests.cs | 13 +++++++++++++ src/shared/Core/StreamExtensions.cs | 9 +++++---- 2 files changed, 18 insertions(+), 4 deletions(-) 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);