Skip to content
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

Fix building slnf with @ in the path #11421

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

surayya-MS
Copy link
Member

@surayya-MS surayya-MS commented Feb 11, 2025

Context

Fixes #11050

If the path to the solution file contains @, it builds normally. But, if solution filter references this solution then the build fails:

{my-path-to}/bugtest%40commithash/Solution/Solution.sln : Solution file error MSB5026: The solution filter file at "{my-path-to}/bugtest@commithash/Solution/Test.slnf" specifies there will be a solution file at "{my-path-to}/bugtest%40commithash/Solution/Solution.sln", but that file does not exist.

same happens with other symbols like % and $.

See the issue description for more details.

Details

The problem occurs on this line:

return FileUtilities.GetFullPath(solution.GetProperty("path").GetString(), Path.GetDirectoryName(solutionFilterFile));

FileUtilities.GetFullPath changes @ to %40.

Specifically this happens here:

string fullPath = EscapingUtilities.Escape(NormalizePath(Path.Combine(currentDirectory, fileSpec)));

Changes

Added bool escape param to FileUtilities.GetFullPath to be able to skip escape for getting solution path from solution filter (.slnf) json

Testing

Added new test to cover this scenario

@@ -658,7 +658,7 @@ internal static string ParseSolutionFromSolutionFilter(string solutionFilterFile
JsonDocumentOptions options = new JsonDocumentOptions() { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip };
JsonDocument text = JsonDocument.Parse(File.ReadAllText(solutionFilterFile), options);
solution = text.RootElement.GetProperty("solution");
return FileUtilities.GetFullPath(solution.GetProperty("path").GetString(), Path.GetDirectoryName(solutionFilterFile));
return FileUtilities.GetFullPath(solution.GetProperty("path").GetString(), Path.GetDirectoryName(solutionFilterFile), escape: false);
Copy link
Member

Choose a reason for hiding this comment

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

Could this be

Suggested change
return FileUtilities.GetFullPath(solution.GetProperty("path").GetString(), Path.GetDirectoryName(solutionFilterFile), escape: false);
return FileUtilities.NormalizePath(Path.GetDirectoryName(solutionFilterFile), solution.GetProperty("path").GetString());

without changing GetFullPath?

Copy link
Member Author

@surayya-MS surayya-MS Feb 12, 2025

Choose a reason for hiding this comment

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

this won't work because in GetFullPath before normalization the solution path that is provided in slnf needs to be fixed for the current machine.

fileSpec = FixFilePath(EscapingUtilities.UnescapeAll(fileSpec));

I can create new function GetFullPathUnescaped and duplicate the code there. What do you think?

src/Shared/FileUtilities.cs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fatal crash if solution filter is built from within a path that contains an @ sign
2 participants