Browse Source

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.
v0.7.4-release
isaacs 15 years ago
committed by Ryan Dahl
parent
commit
3b8e47755a
  1. 13
      src/node.js

13
src/node.js

@ -667,13 +667,17 @@ var posix = posixModule.exports;
var pathModule = createInternalModule("path", function (exports) { var pathModule = createInternalModule("path", function (exports) {
exports.join = function () { exports.join = function () {
var joined = ""; var joined = "",
dotre = /^\.\//g,
dotreplace = "",
dotdotre = /(^|(\/)([^\/]+\/)?)\.\.\//g,
dotdotreplace = ""
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
var part = arguments[i].toString(); var part = arguments[i].toString();
/* Some logic to shorten paths */ /* Some logic to shorten paths */
if (part === ".") continue; if (part === ".") continue;
while (/^\.\//.exec(part)) part = part.replace(/^\.\//, ""); while (dotre.exec(part)) part.replace(dotre, dotreplace);
if (i === 0) { if (i === 0) {
part = part.replace(/\/*$/, "/"); part = part.replace(/\/*$/, "/");
@ -684,7 +688,10 @@ var pathModule = createInternalModule("path", function (exports) {
} }
joined += part; joined += part;
} }
// replace /foo/../bar/baz with /bar/baz
while (dotdotre.exec(joined)) joined.replace(dotdotre, dotdotreplace);
return joined; return joined;
}; };
exports.dirname = function (path) { exports.dirname = function (path) {
@ -840,6 +847,8 @@ Module.prototype.loadObject = function (filename, loadPromise) {
function cat (id, loadPromise) { function cat (id, loadPromise) {
var promise; var promise;
debug(id);
if (id.match(/^http:\/\//)) { if (id.match(/^http:\/\//)) {
promise = new process.Promise(); promise = new process.Promise();
loadModule('http', process.mainModule) loadModule('http', process.mainModule)

Loading…
Cancel
Save