Skip to content

Commit 75487f0

Browse files
targosjasnell
authored andcommitted
module: fix resolution of filename with trailing slash
A recent optimization of module loading performance [1] forgot to check that extensions were set in a certain code path. [1] ae18bbe Fixes: #6214 PR-URL: #6215 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 8636af1 commit 75487f0

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

lib/module.js

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ Module._findPath = function(request, paths) {
170170
}
171171

172172
if (!filename) {
173+
if (exts === undefined)
174+
exts = Object.keys(Module._extensions);
173175
filename = tryPackage(basePath, exts);
174176
}
175177

test/fixtures/module-require/not-found/node_modules/module1/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('module1/');

test/parallel/test-require-exceptions.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@ assert.throws(function() {
1414

1515
// Requiring a module that does not exist should throw an
1616
// error with its `code` set to MODULE_NOT_FOUND
17-
assert.throws(function() {
18-
require(common.fixturesDir + '/DOES_NOT_EXIST');
19-
}, function(e) {
20-
assert.equal('MODULE_NOT_FOUND', e.code);
21-
return true;
22-
});
17+
assertModuleNotFound('/DOES_NOT_EXIST');
18+
19+
assertExists('/module-require/not-found/trailingSlash.js');
20+
assertExists('/module-require/not-found/node_modules/module1/package.json');
21+
assertModuleNotFound('/module-require/not-found/trailingSlash');
22+
23+
function assertModuleNotFound(path) {
24+
assert.throws(function() {
25+
require(common.fixturesDir + path);
26+
}, function(e) {
27+
assert.strictEqual(e.code, 'MODULE_NOT_FOUND');
28+
return true;
29+
});
30+
}
31+
32+
function assertExists(fixture) {
33+
assert(common.fileExists(common.fixturesDir + fixture));
34+
}

0 commit comments

Comments
 (0)