File tree 1 file changed +6
-6
lines changed
src/Cli/dotnet/commands/dotnet-sln/add
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -32,11 +32,11 @@ private static string GetSolutionFolderPathWithForwardSlashes(string path)
32
32
return "/" + string . Join ( "/" , PathUtility . GetPathWithDirectorySeparator ( path ) . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) ) + "/" ;
33
33
}
34
34
35
- private static bool IsValidSolutionFolderPath ( string pathFragment )
35
+ private static bool IsSolutionFolderPathInDirectoryScope ( string relativePath )
36
36
{
37
- return ! string . IsNullOrEmpty ( pathFragment ) && ! pathFragment
38
- . Split ( Path . DirectorySeparatorChar )
39
- . Any ( pathFragment => pathFragment == ".." || pathFragment == "." || Path . GetInvalidFileNameChars ( ) . Any ( c => pathFragment . Contains ( c ) ) ) ;
37
+ return ! string . IsNullOrEmpty ( relativePath )
38
+ && ! Path . IsPathRooted ( relativePath ) // This means path is in a different volume
39
+ && ! relativePath . StartsWith ( ".." ) ; // This means path is outside the solution directory
40
40
}
41
41
42
42
public AddProjectToSolutionCommand ( ParseResult parseResult ) : base ( parseResult )
@@ -137,8 +137,8 @@ private async Task AddProjectsToSolutionAsync(IEnumerable<string> projectPaths,
137
137
relativeSolutionFolderPath = Path . Combine ( [ .. relativeSolutionFolderPath . Split ( Path . DirectorySeparatorChar ) . SkipLast ( 1 ) ] ) ;
138
138
}
139
139
140
- // If the generated path is invalid, make it empty
141
- if ( ! IsValidSolutionFolderPath ( relativeSolutionFolderPath ) )
140
+ // If the generated path is outside the solution directory, we need to set it to empty
141
+ if ( ! IsSolutionFolderPathInDirectoryScope ( relativeSolutionFolderPath ) )
142
142
{
143
143
relativeSolutionFolderPath = string . Empty ;
144
144
}
You can’t perform that action at this time.
0 commit comments