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

IPurePath.Join() does not join paths if both paths are 'rooted' #16

Open
jeffward01 opened this issue May 22, 2022 · 1 comment
Open

Comments

@jeffward01
Copy link
Contributor

jeffward01 commented May 22, 2022

This is a continuation of my previous issue #15 - I wanted to keep the two items seperate because technically they are different issues.

image

If I provide (2) paths to IPurePath.Join() such as:

  • c:\someOther\directoryName\
  • \someFileName.exe
var path = new MockPath(@"c:\ProgramFiles\");
var joined = path.Join(@"c:\someOther\directoryName\",@"\someFile.exe");

// I can also provide these arguments and the same results as below will occur:
var joined = path.Join(@"c:\someOther\directoryName",@"\someFile.exe");

Exepected Result

Option 1: Be smart
Note: This might have some issues with Unix systems and might not be a viable option. See Option 2 and 3.

  • Be smart and use the first rooted and (fully qualified) absolute path, then merge that with the rooted (relative) path | (This is for IPurePath)

  • c:\someOther\directoryName\someFile.exe

joined.ToString() == @"c:\someOther\directoryName\someFile.exe";

Option 2: Be safe
^^ This gets a bit tricky with Unix Systems, so perhaps we throw an exception if (2) rooted paths are provided which are both fully qualified due to unix path formats it cannot be determined which is the relative path?

  • If two rooted paths are provided, we throw an exception | (This is for IPurePath)

Option 3: Be safe, and almost smart

  • If two rooted paths are provided, we throw an exception | (This is for IPurePath)
  • If two rooted paths are provided, but one of them has a 'drive' path (windows), we use that as the 'base fully qualified absolute path, then merge the other paths with it. | (This is for IPurePath)

Actual Result

The result will return c:\someFileName.exe

joined.ToString() == @"c:\someFile.exe";

My vote is for Option 3 as the method already tries to 'be smart' by appending the c: to the \someFileName.exe and makes that decision on its own.

Would love to know your thoughts! IMO we should be as cross platform friendly (safe) as possible

@nemec
Copy link
Owner

nemec commented May 22, 2022

I hope my comment in #15 mostly explain things, but I wanted to add one point here.

If two rooted paths are provided, we throw an exception

Given that Join supports a variable number of arguments (as does the constructor), I think it's important that each of the following produce the same results:

var path = new PureWindowsPath(@"c:\ProgramFiles\", @"c:\someOther\directoryName\", @"\someFile.exe");
var path = new PureWindowsPath(@"c:\ProgramFiles\")
    .Join(@"c:\someOther\directoryName\", @"\someFile.exe");
var path = new PureWindowsPath(@"c:\ProgramFiles\")
    .Join(@"c:\someOther\directoryName\")
    .Join(@"\someFile.exe");

So the behavior should not rely on "two rooted paths", but compare the result of the last join to the next path component.

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

No branches or pull requests

2 participants