From 6b920fa5e6f4e3ddf0afb78a3764ff86134c5462 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 12 Apr 2013 13:15:44 -0700 Subject: [PATCH] Don't prefix paths with drive letters with dots in `mkdirpSync`. [closes #238] Former-commit-id: dd0c8d7b1906210e5f26604d4149ba542727c78d --- build/util.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build/util.js b/build/util.js index d882e9533..851eb55aa 100755 --- a/build/util.js +++ b/build/util.js @@ -9,6 +9,9 @@ /** Load other modules */ var _ = require('../lodash.js'); + /** Used to indicate if running in Windows */ + var isWindows = process.platform == 'win32'; + /*--------------------------------------------------------------------------*/ /** @@ -17,7 +20,7 @@ * @memberOf util.path * @type String */ - var sep = path.sep || (process.platform == 'win32' ? '\\' : '/'); + var sep = path.sep || (isWindows ? '\\' : '/'); /** * The escaped path separator used for inclusion in RegExp strings. @@ -27,6 +30,9 @@ */ var sepEscaped = sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + /** Used to determine if a path is prefixed with a drive letter, dot, or slash */ + var rePrefixed = RegExp('^(?:' + (isWindows ? '[a-zA-Z]:|' : '') + '\\.?)' + sepEscaped); + /*--------------------------------------------------------------------------*/ /** @@ -39,7 +45,7 @@ */ function mkdirpSync(dirname, mode) { // ensure relative paths are prefixed with `./` - if (!RegExp('^\\.?' + sepEscaped).test(dirname)) { + if (!rePrefixed.test(dirname)) { dirname = '.' + sep + dirname; } dirname.split(sep).reduce(function(currPath, segment) {