Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: fix resolution of filename with trailing slash #6215

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}