Skip to content

Commit

Permalink
module: fix resolution of filename with trailing slash
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
targos authored and jasnell committed Apr 20, 2016
1 parent 8636af1 commit 75487f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ Module._findPath = function(request, paths) {
}

if (!filename) {
if (exts === undefined)
exts = Object.keys(Module._extensions);
filename = tryPackage(basePath, exts);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/module-require/not-found/trailingSlash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('module1/');
24 changes: 18 additions & 6 deletions test/parallel/test-require-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ assert.throws(function() {

// Requiring a module that does not exist should throw an
// error with its `code` set to MODULE_NOT_FOUND
assert.throws(function() {
require(common.fixturesDir + '/DOES_NOT_EXIST');
}, function(e) {
assert.equal('MODULE_NOT_FOUND', e.code);
return true;
});
assertModuleNotFound('/DOES_NOT_EXIST');

assertExists('/module-require/not-found/trailingSlash.js');
assertExists('/module-require/not-found/node_modules/module1/package.json');
assertModuleNotFound('/module-require/not-found/trailingSlash');

function assertModuleNotFound(path) {
assert.throws(function() {
require(common.fixturesDir + path);
}, function(e) {
assert.strictEqual(e.code, 'MODULE_NOT_FOUND');
return true;
});
}

function assertExists(fixture) {
assert(common.fileExists(common.fixturesDir + fixture));
}

0 comments on commit 75487f0

Please sign in to comment.