Skip to content
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
4 changes: 4 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ Module.prototype.load = function(filename) {
Module.prototype.require = function(path) {
assert(path, 'missing path');
assert(typeof path === 'string', 'path must be a string');
// Ignore part of the path after null character if it exists
if (path.indexOf('\u0000') !== -1) {
path = path.split('\u0000')[0];
}
return Module._load(path, this, /* isMain */ false);
};

Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-require-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ assert.throws(function() {
require(`${common.fixturesDir}/throws_error`);
}, /^Error: blah$/);

// Requiring the module with null character in
// path as first character of a component
assert.throws(function() {
require('../\u0000on');
}, /^Error: Cannot find module '[.]{2}\/'$/);

// Requiring a module that does not exist should throw an
// error with its `code` set to MODULE_NOT_FOUND
assertModuleNotFound('/DOES_NOT_EXIST');
Expand Down