Skip to content

Skip splitting for paths Fixes #48794 #48874

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

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

Conversation

Forgind
Copy link
Contributor

@Forgind Forgind commented May 8, 2025

Fixes #48794

@Copilot 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 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.

@@ -208,7 +208,8 @@ internal async Task<NewCommandStatus> EnterInstallFlowAsync(InstallCommandArgs a

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

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.

@@ -208,7 +208,8 @@ internal async Task<NewCommandStatus> EnterInstallFlowAsync(InstallCommandArgs a

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.

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