File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
src/Cli/dotnet/commands/dotnet-sln/add Expand file tree Collapse file tree 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)
3232 return "/" + string . Join ( "/" , PathUtility . GetPathWithDirectorySeparator ( path ) . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) ) + "/" ;
3333 }
3434
35- private static bool IsValidSolutionFolderPath ( string pathFragment )
35+ private static bool IsSolutionFolderPathInDirectoryScope ( string relativePath )
3636 {
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
4040 }
4141
4242 public AddProjectToSolutionCommand ( ParseResult parseResult ) : base ( parseResult )
@@ -137,8 +137,8 @@ private async Task AddProjectsToSolutionAsync(IEnumerable<string> projectPaths,
137137 relativeSolutionFolderPath = Path . Combine ( [ .. relativeSolutionFolderPath . Split ( Path . DirectorySeparatorChar ) . SkipLast ( 1 ) ] ) ;
138138 }
139139
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 ) )
142142 {
143143 relativeSolutionFolderPath = string . Empty ;
144144 }
You can’t perform that action at this time.
0 commit comments