From 3b8e47755a16c72d7b3509685a89c834c42a9342 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 16 Dec 2009 13:08:14 -0800 Subject: [PATCH] Bugfix: require("../foo") If you have a circular require chain in which one or more of the modules are referenced with a ".." relative path, like require("../foo"), node blows up. This patch un-blows-up that case. There still seem to be issues with circularity, but this solves one of the more obnoxious ones. --- src/node.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/node.js b/src/node.js index 76dd8a6a22..9e7a2532b1 100644 --- a/src/node.js +++ b/src/node.js @@ -667,13 +667,17 @@ var posix = posixModule.exports; var pathModule = createInternalModule("path", function (exports) { exports.join = function () { - var joined = ""; + var joined = "", + dotre = /^\.\//g, + dotreplace = "", + dotdotre = /(^|(\/)([^\/]+\/)?)\.\.\//g, + dotdotreplace = "" for (var i = 0; i < arguments.length; i++) { var part = arguments[i].toString(); /* Some logic to shorten paths */ if (part === ".") continue; - while (/^\.\//.exec(part)) part = part.replace(/^\.\//, ""); + while (dotre.exec(part)) part.replace(dotre, dotreplace); if (i === 0) { part = part.replace(/\/*$/, "/"); @@ -684,7 +688,10 @@ var pathModule = createInternalModule("path", function (exports) { } joined += part; } + // replace /foo/../bar/baz with /bar/baz + while (dotdotre.exec(joined)) joined.replace(dotdotre, dotdotreplace); return joined; + }; exports.dirname = function (path) { @@ -839,6 +846,8 @@ Module.prototype.loadObject = function (filename, loadPromise) { function cat (id, loadPromise) { var promise; + + debug(id); if (id.match(/^http:\/\//)) { promise = new process.Promise();