Skip to content

Commit ba81146

Browse files
committed
git: fix --get-all output parsing bug
Since --null means that each config entry terminates with a null character ('\0') we are left with one extra entry in the array after splitting the string. This is NOT a real entry and we shouldn't return it from the method.
1 parent c552709 commit ba81146

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/shared/Microsoft.Git.CredentialManager/GitConfiguration.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,23 @@ public IEnumerable<string> GetAll(string name)
267267
switch (git.ExitCode)
268268
{
269269
case 0: // OK
270+
string[] entries = data.Split('\0');
271+
272+
// Because each line terminates with the \0 character, splitting leaves us with one
273+
// bogus blank entry at the end of the array which we should ignore
274+
for (var i = 0; i < entries.Length - 1; i++)
275+
{
276+
yield return entries[i];
277+
}
278+
break;
279+
270280
case 1: // No results
271281
break;
282+
272283
default:
273284
_trace.WriteLine($"Failed to get all config entries '{name}' (exit={git.ExitCode}, level={_filterLevel})");
274285
throw CreateGitException(git, $"Failed to get all Git configuration entries '{name}'");
275286
}
276-
277-
string[] entries = data.Split('\0');
278-
foreach (string entry in entries)
279-
{
280-
yield return entry;
281-
}
282287
}
283288
}
284289

0 commit comments

Comments
 (0)