Repository navigation
Fix Resolve-Path -LiteralPath. - #2572
Conversation
|
Hi Charu Bassi (@charub), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
2e71825 to
2a6b9f6
Compare
|
Hi Charu Bassi (@charub), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
|
Re-triggered the builds, because master was broken |
2a6b9f6 to
5d06c95
Compare
|
please add more tests for |
cd58140 to
09ab983
Compare
|
LGTM |
There was a problem hiding this comment.
These comparison is tedious. We can achieve the same with the following:
if (path.IndexOfAny(new char[]{ '\\', '/' }, 0, 1) == 0 && path.Length > 1)
{
treatAsRelative = false;
}
Note that since this code path may be hot, the new char[]{ '\\', '/' } probably should be declared as a static char array in StringLiterals using StringLiterals.DefaultPathSeparator and StringLiterals.AlternatePathSeparator. This is based on Performance considerations.
There was a problem hiding this comment.
How about (path.StartsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.Ordinal) || path.StartsWith(StringLiterals.AlternatePathSeparatorString, StringComparison.Ordinal) && path.length>1
There was a problem hiding this comment.
Why not path.IndexOfAny(new char[]{ '\\', '/' }, 0, 1) == 0? It's concise and efficient -- only check the first character of path essentially.
There was a problem hiding this comment.
Actually the following is better as path may be an empty string.
if (path.Length > 1 && path.IndexOfAny(new char[]{ '\\', '/' }, 0, 1) == 0)
{
treatAsRelative = false;
}
There was a problem hiding this comment.
I think the current check is simple to understand and serves the purpose.
There was a problem hiding this comment.
Please, add more comments explaining what you are doing here. It will be hard to understand the original intention if you look at this code again after some time. This is required by Code comments.
There was a problem hiding this comment.
Added comments to explain the change
There was a problem hiding this comment.
Please fix the indentations before It.
There was a problem hiding this comment.
Fixed the indentation.
There was a problem hiding this comment.
Is the following working the same with your fix?
PS /> New-PSDrive -Name Test -Root / -PSProvider FileSystem
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
Test 7.59 21.22 FileSystem /
PS /> Resolve-Path -LiteralPath Test:/
Path
----
Test:/
09ab983 to
8936b8f
Compare
There was a problem hiding this comment.
Please reverse the order of "path.Length > 1" and (path.StartsWith() || path.StartsWith()), so that we can avoid unnecessary string comparison under some circumstance.
There was a problem hiding this comment.
Reversed the order.
8936b8f to
94ea9d0
Compare
There was a problem hiding this comment.
equal to "" or "/"
One more minor thing. This comment seems not right since the code suggesting "\" or "/".
There was a problem hiding this comment.
Fixed the comment.
Resolving PowerShell#2570. Ignore drive paths in the check. If the input is a drive path, then "\" is passed as the path to GetDriveQualifiedPath with drive info. Since, the path here starts with "\", treatAsRelative is set to false which prevents further formatting of this path. The check is only valid for PSDrives with root path equals to UNC paths or the paths in unix.
94ea9d0 to
513de17
Compare
Resolving PowerShell#2570. Ignore drive paths in the check. If the input is a drive path, then "\" is passed as the path to GetDriveQualifiedPath with drive info. Since, the path here starts with "\", treatAsRelative is set to false which prevents further formatting of this path. The check is only valid for PSDrives with root path equals to UNC paths or the paths in unix.
Resolving #2570.
Ignore drive paths in the check. If the input is a drive path, then "" is passed as the path to GetDriveQualifiedPath with drive info. Since, the path here starts with "", treatAsRelative is set to false
which prevents further formatting of this path. The check is only valid for PSDrives with root path equals to UNC paths or the paths in unix.