From 6fc5e953547bfbdf97bc380d4bfc471e3378fad9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= <mic.besace@gmail.com>
Date: Wed, 18 Mar 2015 08:38:00 +0100
Subject: [PATCH] module: allow require('.')

Previously, the minimal argument to require the current directory was
require('./'). This commits allows to skip the trailing slash.

Fixes: https://github.com/iojs/io.js/issues/1178
PR-URL: https://github.com/iojs/io.js/pull/1185
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Christian Tellnes <christian@tellnes.no>
Reviewed-By: Roman Reiss <me@silverwind.io>
---
 lib/module.js                                      | 2 +-
 test/fixtures/module-require/relative/dot-slash.js | 1 +
 test/fixtures/module-require/relative/dot.js       | 1 +
 test/fixtures/module-require/relative/index.js     | 1 +
 test/parallel/test-require-extensions-main.js      | 6 ++++++
 5 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 test/fixtures/module-require/relative/dot-slash.js
 create mode 100644 test/fixtures/module-require/relative/dot.js
 create mode 100644 test/fixtures/module-require/relative/index.js

diff --git a/lib/module.js b/lib/module.js
index 30e1f72a256855..b2ddbd80c31913 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -205,7 +205,7 @@ Module._resolveLookupPaths = function(request, parent) {
   }
 
   var start = request.substring(0, 2);
-  if (start !== './' && start !== '..') {
+  if (start !== '.' && start !== './' && start !== '..') {
     var paths = modulePaths;
     if (parent) {
       if (!parent.paths) parent.paths = [];
diff --git a/test/fixtures/module-require/relative/dot-slash.js b/test/fixtures/module-require/relative/dot-slash.js
new file mode 100644
index 00000000000000..9817d8d4a6b4a2
--- /dev/null
+++ b/test/fixtures/module-require/relative/dot-slash.js
@@ -0,0 +1 @@
+module.exports = require('./');
diff --git a/test/fixtures/module-require/relative/dot.js b/test/fixtures/module-require/relative/dot.js
new file mode 100644
index 00000000000000..edac839e948e8b
--- /dev/null
+++ b/test/fixtures/module-require/relative/dot.js
@@ -0,0 +1 @@
+module.exports = require('.');
diff --git a/test/fixtures/module-require/relative/index.js b/test/fixtures/module-require/relative/index.js
new file mode 100644
index 00000000000000..f16abdc55b3f4c
--- /dev/null
+++ b/test/fixtures/module-require/relative/index.js
@@ -0,0 +1 @@
+exports.value = 42;
diff --git a/test/parallel/test-require-extensions-main.js b/test/parallel/test-require-extensions-main.js
index 032f2eb2c983da..2a102afc950f77 100644
--- a/test/parallel/test-require-extensions-main.js
+++ b/test/parallel/test-require-extensions-main.js
@@ -2,3 +2,9 @@ var common = require('../common');
 var assert = require('assert');
 
 require(common.fixturesDir + '/require-bin/bin/req.js');
+
+var a = require(common.fixturesDir + '/module-require/relative/dot.js');
+var b = require(common.fixturesDir + '/module-require/relative/dot-slash.js');
+
+assert.equal(a.value, 42);
+assert.equal(a, b, 'require(".") should resolve like require("./")');