Browse Source

fix infinite loop

contingency-plan
Rich Harris 10 years ago
parent
commit
0d32366539
  1. 16
      src/utils/path.js

16
src/utils/path.js

@ -32,12 +32,11 @@ export function relative ( from, to ) {
} }
while ( toParts[0] && toParts[0][0] === '.' ) { while ( toParts[0] && toParts[0][0] === '.' ) {
if ( toParts[0] === '.' ) { const toPart = toParts.shift();
toParts.shift(); if ( toPart === '..' ) {
} else if ( toParts[0] === '..' ) {
fromParts.pop(); fromParts.pop();
} else { } else if ( toPart !== '.' ) {
throw new Error( `Unexpected path part (${toParts[0]})` ); throw new Error( `Unexpected path part (${toPart})` );
} }
} }
@ -58,10 +57,11 @@ export function resolve ( ...paths ) {
const parts = path.split( /[\/\\]/ ); const parts = path.split( /[\/\\]/ );
while ( parts[0] && parts[0][0] === '.' ) { while ( parts[0] && parts[0][0] === '.' ) {
if ( parts[0] === '.' ) { const part = parts.shift();
parts.shift(); if ( part === '..' ) {
} else if ( parts[0] === '..' ) {
resolvedParts.pop(); resolvedParts.pop();
} else if ( part !== '.' ) {
throw new Error( `Unexpected path part (${part})` );
} }
} }

Loading…
Cancel
Save