Permalink
Browse files

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.
  • Loading branch information...
1 parent bfa3613 commit 3b8e47755a16c72d7b3509685a89c834c42a9342 isaacs committed with ry Dec 16, 2009
Showing with 11 additions and 2 deletions.
  1. +11 −2 src/node.js
View
@@ -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();

0 comments on commit 3b8e477

Please sign in to comment.