mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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.
This commit is contained in:
parent
bfa36136da
commit
3b8e47755a
13
src/node.js
13
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();
|
||||
|
Loading…
Reference in New Issue
Block a user