diff --git a/lib/module.js b/lib/module.js index ae6f4ff453ccc7..56f500b274dbf4 100644 --- a/lib/module.js +++ b/lib/module.js @@ -510,6 +510,8 @@ 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 + path = path.split('\u0000')[0]; return Module._load(path, this, /* isMain */ false); }; diff --git a/test/parallel/test-require-exceptions.js b/test/parallel/test-require-exceptions.js index 0be6b633bf9ed4..70832d29589428 100644 --- a/test/parallel/test-require-exceptions.js +++ b/test/parallel/test-require-exceptions.js @@ -33,10 +33,11 @@ assert.throws(function() { require(`${common.fixturesDir}/throws_error`); }, /^Error: blah$/); -// Requiring the module with null character +// Requiring the module with null character in +// path as first character of a component assert.throws(function() { require('../\u0000on'); -}, /^Error: blah$/); //TODO: Fix the acual error +}, /^Error: Cannot find module '[.]{2}\/'$/); // Requiring a module that does not exist should throw an // error with its `code` set to MODULE_NOT_FOUND