From 1039ab115369640766c900c35c02f97900864010 Mon Sep 17 00:00:00 2001 From: Anirudh Agnihotry Date: Tue, 27 Feb 2018 12:04:53 -0800 Subject: Tests For GetPathRoot and Enabling NormalizeDirectorySeparatorTests (#27494) Corrects its Implementation too Signed-off-by: dotnet-bot-corefx-mirror Signed-off-by: dotnet-bot --- .../shared/System/IO/PathInternal.Windows.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs index 433d6b6a3..f931380c7 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs @@ -190,6 +190,7 @@ namespace System.IO int i = 0; int volumeSeparatorLength = 2; // Length to the colon "C:" int uncRootLength = 2; // Length to the start of the server name "\\" + int devicePrefixLength = PathInternal.ExtendedPathPrefix.Length; bool deviceSyntax = IsDevice(path); bool deviceUnc = deviceSyntax && IsDeviceUNC(path); @@ -201,10 +202,10 @@ namespace System.IO // "\\" -> "\\?\UNC\" uncRootLength = UncExtendedPathPrefix.Length; } - else + else if (devicePrefixLength + 1 < pathLength && path[devicePrefixLength + 1] == VolumeSeparatorChar && IsValidDriveChar(path[devicePrefixLength])) { // "C:" -> "\\?\C:" - volumeSeparatorLength += ExtendedPathPrefix.Length; + volumeSeparatorLength += devicePrefixLength; } } @@ -233,7 +234,18 @@ namespace System.IO if (pathLength >= volumeSeparatorLength + 1 && IsDirectorySeparator(path[volumeSeparatorLength])) i++; } - return i; + else if (deviceSyntax && ((devicePrefixLength + 1 >= pathLength) || !(path[devicePrefixLength + 1] == VolumeSeparatorChar))) + { + i = devicePrefixLength; + int n = 1; // Maximum separators to skip + while (i < pathLength && (!IsDirectorySeparator(path[i]) || --n > 0)) + i++; + + if (i == devicePrefixLength) + i--; + } + + return (i < pathLength && IsDirectorySeparator(path[i])) ? i + 1 : i; } private static bool StartsWithOrdinal(ReadOnlySpan source, string value) -- cgit v1.2.3