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] ae18bbef48
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:
parent
8636af1012
commit
75487f0db8
@ -170,6 +170,8 @@ Module._findPath = function(request, paths) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
|
if (exts === undefined)
|
||||||
|
exts = Object.keys(Module._extensions);
|
||||||
filename = tryPackage(basePath, exts);
|
filename = tryPackage(basePath, exts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
test/fixtures/module-require/not-found/node_modules/module1/package.json
generated
vendored
Normal file
3
test/fixtures/module-require/not-found/node_modules/module1/package.json
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"main": "doesnotexist"
|
||||||
|
}
|
1
test/fixtures/module-require/not-found/trailingSlash.js
vendored
Normal file
1
test/fixtures/module-require/not-found/trailingSlash.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
require('module1/');
|
@ -14,9 +14,21 @@ assert.throws(function() {
|
|||||||
|
|
||||||
// Requiring a module that does not exist should throw an
|
// Requiring a module that does not exist should throw an
|
||||||
// error with its `code` set to MODULE_NOT_FOUND
|
// error with its `code` set to MODULE_NOT_FOUND
|
||||||
assert.throws(function() {
|
assertModuleNotFound('/DOES_NOT_EXIST');
|
||||||
require(common.fixturesDir + '/DOES_NOT_EXIST');
|
|
||||||
}, function(e) {
|
assertExists('/module-require/not-found/trailingSlash.js');
|
||||||
assert.equal('MODULE_NOT_FOUND', e.code);
|
assertExists('/module-require/not-found/node_modules/module1/package.json');
|
||||||
return true;
|
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));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user