Skip to content

Conversation

@Forgind
Copy link
Contributor

@Forgind Forgind commented May 8, 2025

Fixes #48794

Copilot AI review requested due to automatic review settings May 8, 2025 18:14
@Forgind Forgind requested a review from a team as a code owner May 8, 2025 18:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issue #48794 by preventing unintended splitting of package paths.

  • Introduces a check to determine if a package argument is a valid file or directory.
  • Uses this check to conditionally skip path splitting, treating the entire argument as a package path if it exists.

List<InstallRequest> installRequests = new();

foreach (string installArg in args.TemplatePackages)
{
Copy link

Copilot AI May 8, 2025

Choose a reason for hiding this comment

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

Consider adding a comment to explain that the check is used to skip splitting for arguments that represent existing file or directory paths, which will help future maintainers understand the purpose of this logic.

Suggested change
{
{
// Check if the argument represents an existing file or directory path.
// If it is a path, skip splitting the argument, as it is already in the desired format.

Copilot uses AI. Check for mistakes.
foreach (string installArg in args.TemplatePackages)
{
string[] split = installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries).SelectMany(arg => arg.Split('@', StringSplitOptions.RemoveEmptyEntries)).ToArray();
bool isPath = File.Exists(installArg) || Directory.Exists(installArg);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't there something to check if it is a path? Like, something related to that RelativePath utility thing. Because you shouldn't need to check if something is on-disk to know if the argument is a path or not.

Copy link
Member

@nagilson nagilson May 13, 2025

Choose a reason for hiding this comment

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

We could call http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx Path.GetFullPath and catch the exception to see if it's not a path?

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 don't know that I agree with this. If you want to dotnet new install something in your current directory, it would be very hard to tell (without checking if it exists) that it's a path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And if you were to just check for an exception from Path.GetFullPath, I think ~any package would show up as a path

Copy link
Member

@nagilson nagilson left a comment

Choose a reason for hiding this comment

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

This change looks important, I think this is a good way to do it. May you also please add a theory test to prevent regression of this behavior with paths on linux/osx/win?

@Forgind
Copy link
Contributor Author

Forgind commented May 13, 2025

This change looks important, I think this is a good way to do it. May you also please add a theory test to prevent regression of this behavior with paths on linux/osx/win?

Test added. The temp path should be OS-specific to some extent, so I think that would cover all those cases and would mean that you don't need OS-specific Facts.

@marcpopMSFT
Copy link
Member

Note: Ready for review and merge.

@MiYanni MiYanni merged commit 02ab00a into dotnet:main May 19, 2025
30 checks passed
@baronfel
Copy link
Member

/backport to release/9.0.3xx

@github-actions
Copy link
Contributor

Started backporting to release/9.0.3xx: https://github.com/dotnet/sdk/actions/runs/17869154103

@github-actions
Copy link
Contributor

@baronfel backporting to "release/9.0.3xx" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Skip splitting for paths
Using index info to reconstruct a base tree...
M	src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs
Applying: Add test
Using index info to reconstruct a base tree...
A	test/dotnet-new.IntegrationTests/DotnetNewInstallTests.cs
Falling back to patching base and 3-way merge...
Auto-merging test/dotnet-new.Tests/DotnetNewInstallTests.cs
CONFLICT (content): Merge conflict in test/dotnet-new.Tests/DotnetNewInstallTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 Add test
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

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.

Templating workflows broken for paths with special characters on MacOS since SDK 9.0.200

5 participants