summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Böhm <me@feedic.com>2013-01-16 19:53:16 +0100
committerisaacs <i@izs.me>2013-01-16 12:25:06 -0800
commit7465cf911ab944aece1463bc22c96f050751d9a2 (patch)
tree535cbc58a4e0793239123cd839acce0d02d3fa31
parentb9ffc537e66eddc460b5f0d4f7fbdb1880eac96c (diff)
downloadnodejs-7465cf911ab944aece1463bc22c96f050751d9a2.tar.gz
nodejs-7465cf911ab944aece1463bc22c96f050751d9a2.tar.bz2
nodejs-7465cf911ab944aece1463bc22c96f050751d9a2.zip
module: assert that require() is called with a string
as requested in #4577
-rw-r--r--lib/module.js1
-rw-r--r--test/simple/test-module-loading.js9
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/module.js b/lib/module.js
index 1d9e5d1d5..67a95f075 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -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);
};
diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js
index eadd6679c..8a70f214c 100644
--- a/test/simple/test-module-loading.js
+++ b/test/simple/test-module-loading.js
@@ -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');