mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
module: assert that require() is called with a string
as requested in #4577
This commit is contained in:
@@ -359,6 +359,7 @@ Module.prototype.load = function(filename) {
|
||||
|
||||
|
||||
Module.prototype.require = function(path) {
|
||||
assert(typeof path === 'string', 'path must be a string');
|
||||
assert(path, 'missing path');
|
||||
return Module._load(path, this);
|
||||
};
|
||||
|
||||
@@ -295,3 +295,12 @@ process.on('exit', function() {
|
||||
// #1440 Loading files with a byte order marker.
|
||||
assert.equal(42, require('../fixtures/utf8-bom.js'));
|
||||
assert.equal(42, require('../fixtures/utf8-bom.json'));
|
||||
|
||||
// require() must take string, and must be truthy
|
||||
assert.throws(function() {
|
||||
require({ foo: 'bar' });
|
||||
}, 'path must be a string');
|
||||
|
||||
assert.throws(function() {
|
||||
require(false);
|
||||
}, 'missing path');
|
||||
|
||||
Reference in New Issue
Block a user