@@ -206,20 +206,16 @@ const win32 = {
206
206
} else {
207
207
rootEnd = 1 ;
208
208
}
209
- } else if ( isWindowsDeviceRoot ( code ) ) {
209
+ } else if ( isWindowsDeviceRoot ( code ) &&
210
+ path . charCodeAt ( 1 ) === CHAR_COLON ) {
210
211
// Possible device root
211
-
212
- if ( path . charCodeAt ( 1 ) === CHAR_COLON ) {
213
- device = path . slice ( 0 , 2 ) ;
214
- rootEnd = 2 ;
215
- if ( len > 2 ) {
216
- if ( isPathSeparator ( path . charCodeAt ( 2 ) ) ) {
217
- // Treat separator following drive name as an absolute path
218
- // indicator
219
- isAbsolute = true ;
220
- rootEnd = 3 ;
221
- }
222
- }
212
+ device = path . slice ( 0 , 2 ) ;
213
+ rootEnd = 2 ;
214
+ if ( len > 2 && isPathSeparator ( path . charCodeAt ( 2 ) ) ) {
215
+ // Treat separator following drive name as an absolute path
216
+ // indicator
217
+ isAbsolute = true ;
218
+ rootEnd = 3 ;
223
219
}
224
220
}
225
221
} else if ( isPathSeparator ( code ) ) {
@@ -567,26 +563,23 @@ const win32 = {
567
563
568
564
const resolvedPath = win32 . resolve ( path ) ;
569
565
570
- if ( resolvedPath . length >= 3 ) {
571
- if ( resolvedPath . charCodeAt ( 0 ) === CHAR_BACKWARD_SLASH ) {
572
- // Possible UNC root
573
-
574
- if ( resolvedPath . charCodeAt ( 1 ) === CHAR_BACKWARD_SLASH ) {
575
- const code = resolvedPath . charCodeAt ( 2 ) ;
576
- if ( code !== CHAR_QUESTION_MARK && code !== CHAR_DOT ) {
577
- // Matched non-long UNC root, convert the path to a long UNC path
578
- return '\\\\?\\UNC\\' + resolvedPath . slice ( 2 ) ;
579
- }
580
- }
581
- } else if ( isWindowsDeviceRoot ( resolvedPath . charCodeAt ( 0 ) ) ) {
582
- // Possible device root
566
+ if ( resolvedPath . length <= 2 )
567
+ return path ;
583
568
584
- if ( resolvedPath . charCodeAt ( 1 ) === CHAR_COLON &&
585
- resolvedPath . charCodeAt ( 2 ) === CHAR_BACKWARD_SLASH ) {
586
- // Matched device root, convert the path to a long UNC path
587
- return '\\\\?\\' + resolvedPath ;
569
+ if ( resolvedPath . charCodeAt ( 0 ) === CHAR_BACKWARD_SLASH ) {
570
+ // Possible UNC root
571
+ if ( resolvedPath . charCodeAt ( 1 ) === CHAR_BACKWARD_SLASH ) {
572
+ const code = resolvedPath . charCodeAt ( 2 ) ;
573
+ if ( code !== CHAR_QUESTION_MARK && code !== CHAR_DOT ) {
574
+ // Matched non-long UNC root, convert the path to a long UNC path
575
+ return `\\\\?\\UNC\\${ resolvedPath . slice ( 2 ) } ` ;
588
576
}
589
577
}
578
+ } else if ( isWindowsDeviceRoot ( resolvedPath . charCodeAt ( 0 ) ) &&
579
+ resolvedPath . charCodeAt ( 1 ) === CHAR_COLON &&
580
+ resolvedPath . charCodeAt ( 2 ) === CHAR_BACKWARD_SLASH ) {
581
+ // Matched device root, convert the path to a long UNC path
582
+ return `\\\\?\\${ resolvedPath } ` ;
590
583
}
591
584
592
585
return path ;
@@ -749,29 +742,27 @@ const win32 = {
749
742
else if ( end === - 1 )
750
743
end = path . length ;
751
744
return path . slice ( start , end ) ;
752
- } else {
753
- for ( i = path . length - 1 ; i >= start ; -- i ) {
754
- if ( isPathSeparator ( path . charCodeAt ( i ) ) ) {
755
- // If we reached a path separator that was not part of a set of path
756
- // separators at the end of the string, stop now
757
- if ( ! matchedSlash ) {
758
- start = i + 1 ;
759
- break ;
760
- }
761
- } else if ( end === - 1 ) {
762
- // We saw the first non-path separator, mark this as the end of our
763
- // path component
764
- matchedSlash = false ;
765
- end = i + 1 ;
745
+ }
746
+ for ( i = path . length - 1 ; i >= start ; -- i ) {
747
+ if ( isPathSeparator ( path . charCodeAt ( i ) ) ) {
748
+ // If we reached a path separator that was not part of a set of path
749
+ // separators at the end of the string, stop now
750
+ if ( ! matchedSlash ) {
751
+ start = i + 1 ;
752
+ break ;
766
753
}
754
+ } else if ( end === - 1 ) {
755
+ // We saw the first non-path separator, mark this as the end of our
756
+ // path component
757
+ matchedSlash = false ;
758
+ end = i + 1 ;
767
759
}
768
-
769
- if ( end === - 1 )
770
- return '' ;
771
- return path . slice ( start , end ) ;
772
760
}
773
- } ,
774
761
762
+ if ( end === - 1 )
763
+ return '' ;
764
+ return path . slice ( start , end ) ;
765
+ } ,
775
766
776
767
extname ( path ) {
777
768
validateString ( path , 'path' ) ;
@@ -1256,29 +1247,27 @@ const posix = {
1256
1247
else if ( end === - 1 )
1257
1248
end = path . length ;
1258
1249
return path . slice ( start , end ) ;
1259
- } else {
1260
- for ( i = path . length - 1 ; i >= 0 ; -- i ) {
1261
- if ( path . charCodeAt ( i ) === CHAR_FORWARD_SLASH ) {
1262
- // If we reached a path separator that was not part of a set of path
1263
- // separators at the end of the string, stop now
1264
- if ( ! matchedSlash ) {
1265
- start = i + 1 ;
1266
- break ;
1267
- }
1268
- } else if ( end === - 1 ) {
1269
- // We saw the first non-path separator, mark this as the end of our
1270
- // path component
1271
- matchedSlash = false ;
1272
- end = i + 1 ;
1250
+ }
1251
+ for ( i = path . length - 1 ; i >= 0 ; -- i ) {
1252
+ if ( path . charCodeAt ( i ) === CHAR_FORWARD_SLASH ) {
1253
+ // If we reached a path separator that was not part of a set of path
1254
+ // separators at the end of the string, stop now
1255
+ if ( ! matchedSlash ) {
1256
+ start = i + 1 ;
1257
+ break ;
1273
1258
}
1259
+ } else if ( end === - 1 ) {
1260
+ // We saw the first non-path separator, mark this as the end of our
1261
+ // path component
1262
+ matchedSlash = false ;
1263
+ end = i + 1 ;
1274
1264
}
1275
-
1276
- if ( end === - 1 )
1277
- return '' ;
1278
- return path . slice ( start , end ) ;
1279
1265
}
1280
- } ,
1281
1266
1267
+ if ( end === - 1 )
1268
+ return '' ;
1269
+ return path . slice ( start , end ) ;
1270
+ } ,
1282
1271
1283
1272
extname ( path ) {
1284
1273
validateString ( path , 'path' ) ;
0 commit comments