1
0
Fork 0

Fix #1577 once and for all

This guarantees the module resolution doesn't break out of the ArangoDB module root (or the service's root).
This commit is contained in:
Alan Plum 2016-02-26 12:14:15 +01:00
parent 56210b8886
commit 041ebf1542
1 changed files with 5 additions and 0 deletions

View File

@ -63,6 +63,7 @@ delete global.DEFINE_MODULE;
const LOADING = [];
const GLOBAL_PATHS = [];
const ROOT_PATH = fs.normalize(fs.makeAbsolute(internal.startupPath));
global.MODULES_PATH.forEach(function (p) {
p = fs.normalize(fs.makeAbsolute(p));
GLOBAL_PATHS.push(p);
@ -302,6 +303,10 @@ Module._nodeModulePaths = function(from, root) {
var paths = [];
var parts = from.split(splitRe);
var inRoot = root && from.indexOf(root) === 0;
if (!inRoot) {
root = ROOT_PATH;
inRoot = from.indexOf(root) === 0;
}
for (var tip = parts.length - 1; tip >= 0; tip--) {
// don't search in .../node_modules/node_modules