From 788f11dbc7657c033801be4d6cf9ec28fa22a01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Wed, 22 Jul 2015 10:58:50 +0200 Subject: [PATCH] Made `dirname` handle the empty string. --- src/utils/path.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/path.js b/src/utils/path.js index d726b21..b5db7c1 100644 --- a/src/utils/path.js +++ b/src/utils/path.js @@ -11,15 +11,19 @@ export function basename ( path ) { } export function dirname ( path ) { - const match = /(\/|\\)[^\/\\]+$/.exec( path ); + const match = /(\/|\\)[^\/\\]*$/.exec( path ); if ( !match ) return '.'; - return path.slice( 0, -match[0].length ); + + const dir = path.slice( 0, -match[0].length ); + + // If `dir` is the empty string, we're at root. + return dir ? dir : '/'; } export function extname ( path ) { const match = /\.[^\.]+$/.exec( path ); if ( !match ) return ''; - return match[0] + return match[0]; } export function relative ( from, to ) {