@@ -129,6 +129,19 @@ internal static bool IsDevice(ReadOnlySpan<char> path)
129129                ) ; 
130130        } 
131131
132+         /// <summary> 
133+         /// Returns true if the path is a device UNC (\\?\UNC\, \\.\UNC\) 
134+         /// </summary> 
135+         internal  static bool  IsDeviceUNC ( ReadOnlySpan < char >  path ) 
136+         { 
137+             return  path . Length  >=  UncExtendedPrefixLength 
138+                 &&  IsDevice ( path ) 
139+                 &&  IsDirectorySeparator ( path [ 7 ] ) 
140+                 &&  path [ 4 ]  ==  'U' 
141+                 &&  path [ 5 ]  ==  'N' 
142+                 &&  path [ 6 ]  ==  'C' ; 
143+         } 
144+ 
132145        /// <summary> 
133146        /// Returns true if the path uses the canonical form of extended syntax ("\\?\" or "\??\"). If the 
134147        /// path matches exactly (cannot use alternate directory separators) Windows will skip normalization 
@@ -178,12 +191,12 @@ internal static int GetRootLength(ReadOnlySpan<char> path)
178191            int  volumeSeparatorLength  =  2 ;   // Length to the colon "C:" 
179192            int  uncRootLength  =  2 ;           // Length to the start of the server name "\\" 
180193
181-             bool  extendedSyntax  =  StartsWithOrdinal ( path ,   ExtendedPathPrefix ) ; 
182-             bool  extendedUncSyntax  =  StartsWithOrdinal ( path ,   UncExtendedPathPrefix ) ; 
183-             if  ( extendedSyntax ) 
194+             bool  deviceSyntax  =  IsDevice ( path ) ; 
195+             bool  deviceUnc  =  deviceSyntax   &&   IsDeviceUNC ( path ) ; 
196+             if  ( deviceSyntax ) 
184197            { 
185198                // Shift the position we look for the root from to account for the extended prefix 
186-                 if  ( extendedUncSyntax ) 
199+                 if  ( deviceUnc ) 
187200                { 
188201                    // "\\" -> "\\?\UNC\" 
189202                    uncRootLength  =  UncExtendedPathPrefix . Length ; 
@@ -195,12 +208,12 @@ internal static int GetRootLength(ReadOnlySpan<char> path)
195208                } 
196209            } 
197210
198-             if  ( ( ! extendedSyntax  ||  extendedUncSyntax )  &&  pathLength  >  0  &&  IsDirectorySeparator ( path [ 0 ] ) ) 
211+             if  ( ( ! deviceSyntax  ||  deviceUnc )  &&  pathLength  >  0  &&  IsDirectorySeparator ( path [ 0 ] ) ) 
199212            { 
200213                // UNC or simple rooted path (e.g. "\foo", NOT "\\?\C:\foo") 
201214
202215                i  =  1 ;  //  Drive rooted (\foo) is one character 
203-                 if  ( extendedUncSyntax  ||  ( pathLength  >  1  &&  IsDirectorySeparator ( path [ 1 ] ) ) ) 
216+                 if  ( deviceUnc  ||  ( pathLength  >  1  &&  IsDirectorySeparator ( path [ 1 ] ) ) ) 
204217                { 
205218                    // UNC (\\?\UNC\ or \\), scan past the next two directory separators at most 
206219                    // (e.g. to \\?\UNC\Server\Share or \\Server\Share\) 
0 commit comments