mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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] https://github.com/nodejs/node/pull/5172/commits/ae18bbef48d87d9c641df85369f62cfd5ed8c250 Fixes: https://github.com/nodejs/node/issues/6214 PR-URL: https://github.com/nodejs/node/pull/6215 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
This commit is contained in:
1 parent
8636af1012
commit
75487f0db8
4 files changed
+24
-6
No files matched your search
@@ -170,6 +170,8 @@ Module._findPath = function(request, paths) {
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
if (exts === undefined)
|
||||
exts = Object.keys(Module._extensions);
|
||||
filename = tryPackage(basePath, exts);
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"main": "doesnotexist"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
require('module1/');
|
||||
@@ -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));
|
||||
}
|
||||
Reference in new issue
Block a user