Skip to content

Commit

Permalink
path: resolve normalize drive letter to lower case
Browse files Browse the repository at this point in the history
make path.resolve work the same as path.normalize
  • Loading branch information
dead-horse authored and orangemocha committed Oct 20, 2014
1 parent d22637c commit f6e5740
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
'.';
};
Expand Down
5 changes: 3 additions & 2 deletions test/simple/test-module-nodemodulepaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

var common = require('../common');
var assert = require('assert');
var path = require('path');

var module = require('module');

Expand All @@ -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';
Expand All @@ -39,4 +40,4 @@ if (isWindows) {
paths = module._nodeModulePaths(file);

assert.ok(paths.indexOf(file + delimiter + 'node_modules') !== -1);
assert.ok(Array.isArray(paths));
assert.ok(Array.isArray(paths));
2 changes: 1 addition & 1 deletion test/simple/test-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit f6e5740

Please sign in to comment.