@@ -190,7 +190,6 @@ const win32 = {
190190 let resolvedDevice = '' ;
191191 let resolvedTail = '' ;
192192 let resolvedAbsolute = false ;
193- let slashCheck = false ;
194193
195194 for ( let i = args . length - 1 ; i >= - 1 ; i -- ) {
196195 let path ;
@@ -222,10 +221,6 @@ const win32 = {
222221 }
223222 }
224223
225- if ( i === args . length - 1 &&
226- isPathSeparator ( StringPrototypeCharCodeAt ( path , path . length - 1 ) ) ) {
227- slashCheck = true ;
228- }
229224 const len = path . length ;
230225 let rootEnd = 0 ;
231226 let device = '' ;
@@ -273,16 +268,10 @@ const win32 = {
273268 j ++ ;
274269 }
275270 if ( j === len || j !== last ) {
276- if ( firstPart !== '.' && firstPart !== '?' ) {
277- // We matched a UNC root
278- device =
279- `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
280- rootEnd = j ;
281- } else {
282- // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
283- device = `\\\\${ firstPart } ` ;
284- rootEnd = 4 ;
285- }
271+ // We matched a UNC root
272+ device =
273+ `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
274+ rootEnd = j ;
286275 }
287276 }
288277 }
@@ -334,21 +323,9 @@ const win32 = {
334323 resolvedTail = normalizeString ( resolvedTail , ! resolvedAbsolute , '\\' ,
335324 isPathSeparator ) ;
336325
337- if ( ! resolvedAbsolute ) {
338- return `${ resolvedDevice } ${ resolvedTail } ` || '.' ;
339- }
340-
341- if ( resolvedTail . length === 0 ) {
342- return slashCheck ? `${ resolvedDevice } \\` : resolvedDevice ;
343- }
344-
345- if ( slashCheck ) {
346- return resolvedTail === '\\' ?
347- `${ resolvedDevice } \\` :
348- `${ resolvedDevice } \\${ resolvedTail } \\` ;
349- }
350-
351- return `${ resolvedDevice } \\${ resolvedTail } ` ;
326+ return resolvedAbsolute ?
327+ `${ resolvedDevice } \\${ resolvedTail } ` :
328+ `${ resolvedDevice } ${ resolvedTail } ` || '.' ;
352329 } ,
353330
354331 /**
@@ -404,22 +381,17 @@ const win32 = {
404381 ! isPathSeparator ( StringPrototypeCharCodeAt ( path , j ) ) ) {
405382 j ++ ;
406383 }
407- if ( j === len || j !== last ) {
408- if ( firstPart === '.' || firstPart === '?' ) {
409- // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
410- device = `\\\\${ firstPart } ` ;
411- rootEnd = 4 ;
412- } else if ( j === len ) {
413- // We matched a UNC root only
414- // Return the normalized version of the UNC root since there
415- // is nothing left to process
416- return `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last ) } \\` ;
417- } else {
418- // We matched a UNC root with leftovers
419- device =
420- `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
421- rootEnd = j ;
422- }
384+ if ( j === len ) {
385+ // We matched a UNC root only
386+ // Return the normalized version of the UNC root since there
387+ // is nothing left to process
388+ return `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last ) } \\` ;
389+ }
390+ if ( j !== last ) {
391+ // We matched a UNC root with leftovers
392+ device =
393+ `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
394+ rootEnd = j ;
423395 }
424396 }
425397 }
@@ -1190,7 +1162,6 @@ const posix = {
11901162 resolve ( ...args ) {
11911163 let resolvedPath = '' ;
11921164 let resolvedAbsolute = false ;
1193- let slashCheck = false ;
11941165
11951166 for ( let i = args . length - 1 ; i >= 0 && ! resolvedAbsolute ; i -- ) {
11961167 const path = args [ i ] ;
@@ -1200,17 +1171,8 @@ const posix = {
12001171 if ( path . length === 0 ) {
12011172 continue ;
12021173 }
1203- if ( i === args . length - 1 &&
1204- isPosixPathSeparator ( StringPrototypeCharCodeAt ( path ,
1205- path . length - 1 ) ) ) {
1206- slashCheck = true ;
1207- }
12081174
1209- if ( resolvedPath . length !== 0 ) {
1210- resolvedPath = `${ path } /${ resolvedPath } ` ;
1211- } else {
1212- resolvedPath = path ;
1213- }
1175+ resolvedPath = `${ path } /${ resolvedPath } ` ;
12141176 resolvedAbsolute =
12151177 StringPrototypeCharCodeAt ( path , 0 ) === CHAR_FORWARD_SLASH ;
12161178 }
@@ -1229,20 +1191,10 @@ const posix = {
12291191 resolvedPath = normalizeString ( resolvedPath , ! resolvedAbsolute , '/' ,
12301192 isPosixPathSeparator ) ;
12311193
1232- if ( ! resolvedAbsolute ) {
1233- if ( resolvedPath . length === 0 ) {
1234- return '.' ;
1235- }
1236- if ( slashCheck ) {
1237- return `${ resolvedPath } /` ;
1238- }
1239- return resolvedPath ;
1240- }
1241-
1242- if ( resolvedPath . length === 0 || resolvedPath === '/' ) {
1243- return '/' ;
1194+ if ( resolvedAbsolute ) {
1195+ return `/${ resolvedPath } ` ;
12441196 }
1245- return slashCheck ? `/ ${ resolvedPath } /` : `/ ${ resolvedPath } ` ;
1197+ return resolvedPath . length > 0 ? resolvedPath : '.' ;
12461198 } ,
12471199
12481200 /**
@@ -1326,35 +1278,11 @@ const posix = {
13261278 if ( from === to )
13271279 return '' ;
13281280
1329- // Trim any leading slashes
1330- let fromStart = 0 ;
1331- while ( fromStart < from . length &&
1332- StringPrototypeCharCodeAt ( from , fromStart ) === CHAR_FORWARD_SLASH ) {
1333- fromStart ++ ;
1334- }
1335- // Trim trailing slashes
1336- let fromEnd = from . length ;
1337- while (
1338- fromEnd - 1 > fromStart &&
1339- StringPrototypeCharCodeAt ( from , fromEnd - 1 ) === CHAR_FORWARD_SLASH
1340- ) {
1341- fromEnd -- ;
1342- }
1281+ const fromStart = 1 ;
1282+ const fromEnd = from . length ;
13431283 const fromLen = fromEnd - fromStart ;
1344-
1345- // Trim any leading slashes
1346- let toStart = 0 ;
1347- while ( toStart < to . length &&
1348- StringPrototypeCharCodeAt ( to , toStart ) === CHAR_FORWARD_SLASH ) {
1349- toStart ++ ;
1350- }
1351- // Trim trailing slashes
1352- let toEnd = to . length ;
1353- while ( toEnd - 1 > toStart &&
1354- StringPrototypeCharCodeAt ( to , toEnd - 1 ) === CHAR_FORWARD_SLASH ) {
1355- toEnd -- ;
1356- }
1357- const toLen = toEnd - toStart ;
1284+ const toStart = 1 ;
1285+ const toLen = to . length - toStart ;
13581286
13591287 // Compare paths to find the longest common path from root
13601288 const length = ( fromLen < toLen ? fromLen : toLen ) ;
0 commit comments