From 0d323665393764062759dbccd9972b8ff3827f0b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 14 Jul 2015 10:08:57 -0400 Subject: [PATCH] fix infinite loop --- src/utils/path.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils/path.js b/src/utils/path.js index 6023d78..32df39c 100644 --- a/src/utils/path.js +++ b/src/utils/path.js @@ -32,12 +32,11 @@ export function relative ( from, to ) { } while ( toParts[0] && toParts[0][0] === '.' ) { - if ( toParts[0] === '.' ) { - toParts.shift(); - } else if ( toParts[0] === '..' ) { + const toPart = toParts.shift(); + if ( toPart === '..' ) { fromParts.pop(); - } else { - throw new Error( `Unexpected path part (${toParts[0]})` ); + } else if ( toPart !== '.' ) { + throw new Error( `Unexpected path part (${toPart})` ); } } @@ -58,10 +57,11 @@ export function resolve ( ...paths ) { const parts = path.split( /[\/\\]/ ); while ( parts[0] && parts[0][0] === '.' ) { - if ( parts[0] === '.' ) { - parts.shift(); - } else if ( parts[0] === '..' ) { + const part = parts.shift(); + if ( part === '..' ) { resolvedParts.pop(); + } else if ( part !== '.' ) { + throw new Error( `Unexpected path part (${part})` ); } }