Skip to content

Commit b36ab2e

Browse files
authored
Fix bug when adding solution folder containing .. (#46456)
1 parent c490303 commit b36ab2e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Cli/dotnet/commands/dotnet-sln/add/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ private async Task AddProjectsToSolutionAsync(string solutionFileFullPath, IEnum
100100
foreach (var projectPath in projectPaths)
101101
{
102102
string relativePath = Path.GetRelativePath(Path.GetDirectoryName(solutionFileFullPath), projectPath);
103-
// Add fallback solution folder
104-
string relativeSolutionFolder = Path.GetDirectoryName(relativePath);
103+
// Add fallback solution folder if relative path does not contain `..`.
104+
string relativeSolutionFolder = relativePath.Split(Path.DirectorySeparatorChar).Any(p => p == "..")
105+
? string.Empty : Path.GetDirectoryName(relativePath);
106+
105107
if (!_inRoot && solutionFolder is null && !string.IsNullOrEmpty(relativeSolutionFolder))
106108
{
107109
if (relativeSolutionFolder.Split(Path.DirectorySeparatorChar).LastOrDefault() == Path.GetFileNameWithoutExtension(relativePath))

0 commit comments

Comments
 (0)