module: assert that require() is called with a string
authorFelix Böhm <me@feedic.com>
Wed, 16 Jan 2013 18:53:16 +0000 (19:53 +0100)
committerisaacs <i@izs.me>
Wed, 16 Jan 2013 20:25:06 +0000 (12:25 -0800)
as requested in #4577

lib/module.js
test/simple/test-module-loading.js

index 1d9e5d1..67a95f0 100644 (file)
@@ -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);
 };
index eadd667..8a70f21 100644 (file)
@@ -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');