Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 1f28e38

Browse files
Checking for empty paths as well as null
1 parent 88adbf1 commit 1f28e38

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/GitHub.Api/IO/FileSystemHelpers.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ static class FileSystemHelpers
77
{
88
public static string FindCommonPath(IEnumerable<string> paths)
99
{
10-
var pathsArray = paths.Where(s => s != null).Select(s => s.ToNPath().Parent).ToArray();
11-
var maxDepth = pathsArray.Max(path => path.Depth);
12-
var deepestPath = pathsArray.First(path => path.Depth == maxDepth);
10+
var parentPaths = paths.Where(s => !string.IsNullOrEmpty(s)).Select(s => s.ToNPath().Parent);
11+
if (!parentPaths.Any())
12+
return null;
13+
14+
var parentsArray = parentPaths.ToArray();
15+
var maxDepth = parentsArray.Max(path => path.Depth);
16+
var deepestPath = parentsArray.First(path => path.Depth == maxDepth);
1317

1418
var commonParent = deepestPath;
15-
foreach (var path in pathsArray)
19+
foreach (var path in parentsArray)
1620
{
1721
var cp = path.Elements.Any() ? commonParent.GetCommonParent(path) : null;
1822
if (cp != null)

0 commit comments

Comments
 (0)