From f6e574018090ed4d63596b8a3bb614f8f48b6267 Mon Sep 17 00:00:00 2001 From: dead-horse Date: Wed, 17 Sep 2014 18:59:59 +0800 Subject: [PATCH] path: resolve normalize drive letter to lower case make path.resolve work the same as path.normalize --- lib/path.js | 5 +++++ test/simple/test-module-nodemodulepaths.js | 5 +++-- test/simple/test-path.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/path.js b/lib/path.js index 44ef0d68e2..fc5e650ce7 100644 --- a/lib/path.js +++ b/lib/path.js @@ -163,6 +163,11 @@ if (isWindows) { resolvedTail = normalizeArray(resolvedTail.split(/[\\\/]+/).filter(f), !resolvedAbsolute).join('\\'); + // If device is a drive letter, we'll normalize to lower case. + if (resolvedDevice && resolvedDevice.charAt(1) === ':') + resolvedDevice = resolvedDevice[0].toLowerCase() + + resolvedDevice.substr(1); + return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) || '.'; }; diff --git a/test/simple/test-module-nodemodulepaths.js b/test/simple/test-module-nodemodulepaths.js index 3d48d99ab9..af44840b4b 100644 --- a/test/simple/test-module-nodemodulepaths.js +++ b/test/simple/test-module-nodemodulepaths.js @@ -21,6 +21,7 @@ var common = require('../common'); var assert = require('assert'); +var path = require('path'); var module = require('module'); @@ -29,7 +30,7 @@ var isWindows = process.platform === 'win32'; var file, delimiter, paths; if (isWindows) { - file = 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo'; + file = path.normalize('C:\\Users\\Rocko Artischocko\\node_stuff\\foo'); delimiter = '\\' } else { file = '/usr/test/lib/node_modules/npm/foo'; @@ -39,4 +40,4 @@ if (isWindows) { paths = module._nodeModulePaths(file); assert.ok(paths.indexOf(file + delimiter + 'node_modules') !== -1); -assert.ok(Array.isArray(paths)); \ No newline at end of file +assert.ok(Array.isArray(paths)); diff --git a/test/simple/test-path.js b/test/simple/test-path.js index cdeebcd069..b4247f8bf8 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -321,7 +321,7 @@ if (isWindows) { [['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'], [['c:/ignore', 'c:/some/file'], 'c:\\some\\file'], [['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'], - [['.'], process.cwd()], + [['.'], path.normalize(process.cwd())], [['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'], [['c:/', '//'], 'c:\\'], [['c:/', '//dir'], 'c:\\dir'],