Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit f6e5740

Browse files
dead-horseorangemocha
authored andcommitted
path: resolve normalize drive letter to lower case
make path.resolve work the same as path.normalize
1 parent d22637c commit f6e5740

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/path.js

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ if (isWindows) {
163163
resolvedTail = normalizeArray(resolvedTail.split(/[\\\/]+/).filter(f),
164164
!resolvedAbsolute).join('\\');
165165

166+
// If device is a drive letter, we'll normalize to lower case.
167+
if (resolvedDevice && resolvedDevice.charAt(1) === ':')
168+
resolvedDevice = resolvedDevice[0].toLowerCase() +
169+
resolvedDevice.substr(1);
170+
166171
return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) ||
167172
'.';
168173
};

test/simple/test-module-nodemodulepaths.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
var common = require('../common');
2323
var assert = require('assert');
24+
var path = require('path');
2425

2526
var module = require('module');
2627

@@ -29,7 +30,7 @@ var isWindows = process.platform === 'win32';
2930
var file, delimiter, paths;
3031

3132
if (isWindows) {
32-
file = 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo';
33+
file = path.normalize('C:\\Users\\Rocko Artischocko\\node_stuff\\foo');
3334
delimiter = '\\'
3435
} else {
3536
file = '/usr/test/lib/node_modules/npm/foo';
@@ -39,4 +40,4 @@ if (isWindows) {
3940
paths = module._nodeModulePaths(file);
4041

4142
assert.ok(paths.indexOf(file + delimiter + 'node_modules') !== -1);
42-
assert.ok(Array.isArray(paths));
43+
assert.ok(Array.isArray(paths));

test/simple/test-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ if (isWindows) {
321321
[['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'],
322322
[['c:/ignore', 'c:/some/file'], 'c:\\some\\file'],
323323
[['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'],
324-
[['.'], process.cwd()],
324+
[['.'], path.normalize(process.cwd())],
325325
[['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'],
326326
[['c:/', '//'], 'c:\\'],
327327
[['c:/', '//dir'], 'c:\\dir'],

0 commit comments

Comments
 (0)