Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Bug in GetFullPath(basePath, Path) #16598

Merged
merged 4 commits into from
Feb 27, 2018
Merged

Bug in GetFullPath(basePath, Path) #16598

merged 4 commits into from
Feb 27, 2018

Conversation

Anipik
Copy link

@Anipik Anipik commented Feb 27, 2018

This change corrects the Case when base path is a device path and path is a specific drive relative path

@@ -99,7 +99,7 @@ public static string GetFullPath(string path, string basePath)
// No matching root, root to specified drive
// "D:Foo" and "C:\Bar" => "D:Foo"
// "D:\Foo" and "\\?\C:\Bar" => "\\?\D:\Foo"
Copy link
Member

Choose a reason for hiding this comment

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

It should be "D:Foo" and "\\?\C:\Bar" => "\\?\D:\Foo"

@@ -99,7 +99,7 @@ public static string GetFullPath(string path, string basePath)
// No matching root, root to specified drive
// "D:Foo" and "C:\Bar" => "D:Foo"
// "D:\Foo" and "\\?\C:\Bar" => "\\?\D:\Foo"
combinedPath = path.Insert(2, "\\");
combinedPath = PathInternal.IsDevice(basePath) ? basePath.Substring(0,4) + path.Insert(2, "\\") : path.Insert(2, "\\");
Copy link
Member

Choose a reason for hiding this comment

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

You could save some allocations by using CombineNoChecksInternal(). If you take a span and slice it on the original string you can end up with "C:" and "foo". Then you can slice basepath as well if you need the third one.

Copy link
Member

Choose a reason for hiding this comment

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

Note that your other CombineNoChecks usages should probably be CombineNoChecksInternal. I don't think you want the rooting behavior.

// "D:\Foo" and "\\?\C:\Bar" => "\\?\D:\Foo"
combinedPath = path.Insert(2, "\\");
// "D:Foo" and "\\?\C:\Bar" => "\\?\D:\Foo"
combinedPath = PathInternal.IsDevice(basePath) ? CombineNoChecksInternal(basePath.AsSpan().Slice(0, 4), path.AsSpan().Slice(0, 2), "\\", path.AsSpan().Slice(2)) : path.Insert(2, "\\");
Copy link
Member

Choose a reason for hiding this comment

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

Nit- it would be easier to read if "\\" was changed to @"\"

@JeremyKuhne JeremyKuhne merged commit 6a977e9 into dotnet:master Feb 27, 2018
dotnet-bot pushed a commit to dotnet/corert that referenced this pull request Feb 28, 2018
* GetFullPath and GetRootLength Corrected

* Removed getpathroot

* using span

* "\\" changed to @"\"

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas pushed a commit to dotnet/corert that referenced this pull request Feb 28, 2018
* GetFullPath and GetRootLength Corrected

* Removed getpathroot

* using span

* "\\" changed to @"\"

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
A-And pushed a commit to A-And/coreclr that referenced this pull request Feb 28, 2018
* GetFullPath and GetRootLength Corrected

* Removed getpathroot

* using span

* "\\" changed to @"\"
dotnet-bot pushed a commit to dotnet/corefx that referenced this pull request Feb 28, 2018
* GetFullPath and GetRootLength Corrected

* Removed getpathroot

* using span

* "\\" changed to @"\"

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
ahsonkhan pushed a commit to dotnet/corefx that referenced this pull request Mar 1, 2018
* GetFullPath and GetRootLength Corrected

* Removed getpathroot

* using span

* "\\" changed to @"\"

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
kbaladurin pushed a commit to kbaladurin/corert that referenced this pull request Mar 15, 2018
* GetFullPath and GetRootLength Corrected

* Removed getpathroot

* using span

* "\\" changed to @"\"

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
@Anipik Anipik deleted the RootlengthFixed branch March 24, 2018 01:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants