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?

Copy link
Member

Choose a reason for hiding this comment

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

is it possible to do here

string fullPath = NormalizePath(Path.Combine(currentDirectory, FileUtilities.FixFilePath(EscapingUtilities.UnescapeAll(fileSpec)));
instead of making modification of FileUtilities.cs?

Copy link
Member Author

Choose a reason for hiding this comment

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

there is also adding trailing slash at the end of the full path

if (NativeMethodsShared.IsWindows && !EndsWithSlash(fullPath))
{
if (FileUtilitiesRegex.IsDrivePattern(fileSpec) ||
FileUtilitiesRegex.IsUncPattern(fullPath))
{
// append trailing slash if Path.GetFullPath failed to (this happens with drive-specs and UNC shares)
fullPath += Path.DirectorySeparatorChar;
}
}

Not modifying the FileUtilities.GetFullPath by adding extra check makes sense because it is on a hot path. Adding a new method FileUtilities.GetFullPathUnescaped that will duplicate most of the code except escaping would be a compromise for that reason.

Is there other reason not to modify FileUtilities.cs that I miss?

@Mik4sa
Copy link

Mik4sa commented Feb 15, 2025

Could this PR maybe also fix #11442?

@surayya-MS
Copy link
Member Author

Could this PR maybe also fix #11442?

This is probably not related. The bug that this PR fixes is not recent and existed before. The one you described looks like a regression. Nevertheless, we will fix it soon. Thanks for reporting!

@Mik4sa
Copy link

Mik4sa commented Feb 18, 2025

hmm too bad but thank you for your time and feedback :)
I'm looking forward to a fix :)

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
4 participants