Skip to content

Commit 93cada9

Browse files
committed
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<string> 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.
1 parent 0d70623 commit 93cada9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/shared/Core.Tests/StreamExtensionsTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ public void StreamExtensions_ReadMultiDictionary_CaseInsensitive_ReturnsDictiona
254254
AssertMultiDictionary(new[] { "2" }, "a", output);
255255
}
256256

257+
[Fact]
258+
public void StreamExtensions_ReadMultiDictionary_EmptyString_ReturnsKeyWithEmptyStringValue()
259+
{
260+
string input = "a=\n\n";
261+
262+
var output = ReadStringStream(input, StreamExtensions.ReadMultiDictionary);
263+
264+
Assert.NotNull(output);
265+
Assert.Equal(1, output.Count);
266+
267+
AssertMultiDictionary(new[] { String.Empty, }, "a", output);
268+
}
269+
257270
[Fact]
258271
public void StreamExtensions_ReadMultiDictionary_Spaces_ReturnsCorrectKeysAndValues()
259272
{

src/shared/Core/StreamExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,15 @@ private static void ParseMultiLine(IDictionary<string, IList<string>> dict, stri
248248
// Only allow one value for non-multi/array entries ("key=value")
249249
// and reset the array of a multi-entry if the value is empty ("key[]=<empty>")
250250
bool emptyValue = string.IsNullOrEmpty(value);
251+
251252
if (!multi || emptyValue)
252253
{
253254
list.Clear();
255+
}
254256

255-
if (emptyValue)
256-
{
257-
return;
258-
}
257+
if (multi && emptyValue)
258+
{
259+
return;
259260
}
260261

261262
list.Add(value);

0 commit comments

Comments
 (0)