Skip to content

sln-add: Don't add solution folders outside the scope of solution directory #48611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025

Conversation

edvilme
Copy link
Contributor

@edvilme edvilme commented Apr 21, 2025

Fixes #48608

Description

When adding a project to a solution file, solution folders are automatically generated with the relative path (relative to the solution file path). When adding projects outside the scope of the solution working directory, solution folders with invalid names are created (e.g., .., :, etc).

This was addressed in #46456 but didn't consider paths in different volumes.

Risk

Low - this doesn't alter existing behavior but rather considers a previously not considered edge case.

Regression

Yes - this worked before 9.0.2xx

Testing

Adding automated tests is difficult as it involves mounting several volumes, but manual tests were performed.

Expected behavior

image

Current behavior

image

@ghost ghost added Area-CLI untriaged Request triage from a team member labels Apr 21, 2025
@edvilme edvilme changed the title sln-add: Don't add solution folders with invalid chars sln-add: Don't add solution folders with invalid paths Apr 22, 2025
@edvilme edvilme requested a review from Forgind April 22, 2025 16:51
@edvilme edvilme marked this pull request as ready for review April 22, 2025 18:02
@edvilme edvilme requested a review from a team April 22, 2025 18:02
@edvilme edvilme changed the title sln-add: Don't add solution folders with invalid paths sln-add: Don't add solution folders outside the scope of solution directory Apr 22, 2025
Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I generally look favorably upon trying to clean up code, I don't think it's positive in servicing PRs, as it makes it harder to review and can lead to unexpected errors. I found GenerateIntermediateSolutionFoldersForProjectPath particularly confusing. I'm not saying this can't go in, but I don't think it should go into 9.0.3xx as-is.

@@ -31,13 +32,21 @@ private static string GetSolutionFolderPathWithForwardSlashes(string path)
return "/" + string.Join("/", PathUtility.GetPathWithDirectorySeparator(path).Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries)) + "/";
}

private static bool IsSolutionFolderPathInDirectoryScope(string relativePath)
{
return !string.IsNullOrEmpty(relativePath)
Copy link
Contributor

@Forgind Forgind Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for instance, if I had a path like src\Build\..\..\..\..\test\foo...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it is entirely possible to run into this issue since relativePath is obtained through Path.GetRelativePath, which should return the actual resolved path.
So instead of src\Build\..\..\..\..\test\foo, it should be ..\..\test\foo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough; missed that

@edvilme edvilme force-pushed the edvilme-sln-add-invalidchars branch from 835d30c to 0d20f00 Compare April 22, 2025 20:32
@edvilme edvilme requested a review from Forgind April 22, 2025 20:34
@Forgind
Copy link
Contributor

Forgind commented Apr 22, 2025

I think you could potentially be more lenient with things with .. that end up still in the sln's cone, but 🤷

@edvilme edvilme added Servicing-consider and removed untriaged Request triage from a team member labels Apr 22, 2025
@rbhanda rbhanda added this to the 9.0.6 milestone Apr 29, 2025
@edvilme edvilme enabled auto-merge (squash) April 30, 2025 15:28
@edvilme edvilme merged commit 0826cbe into dotnet:release/9.0.3xx May 13, 2025
33 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants