Skip to content
Prev Previous commit
Next Next commit
pr feedback - validations on paths
  • Loading branch information
guybedford committed Aug 6, 2019
commit 9d95b1da4eeb6c6455d69bdc989c25c102dda5a5
18 changes: 9 additions & 9 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,16 @@ function resolveExportsTarget(pkgPath, target, subpath, basePath, mappingKey) {
if (target.startsWith('./') &&
(subpath.length === 0 || target.endsWith('/'))) {
const resolvedTarget = new URL(target, pkgPath);
const pkgPathHref = pkgPath.href;
const resolvedTargetHref = resolvedTarget.href;
if (StringPrototype.startsWith(resolvedTargetHref, pkgPathHref) &&
StringPrototype.indexOf(resolvedTargetHref, '/node_modules/',
pkgPathHref.length - 1) === -1) {
const pkgPathPath = pkgPath.pathname;
const resolvedTargetPath = resolvedTarget.pathname;
if (StringPrototype.startsWith(resolvedTargetPath, pkgPathPath) &&
StringPrototype.indexOf(resolvedTargetPath, '/node_modules/',
pkgPathPath.length - 1) === -1) {
const resolved = new URL(subpath, resolvedTarget);
const resolvedHref = resolved.href;
if (StringPrototype.startsWith(resolvedHref, pkgPathHref) &&
StringPrototype.indexOf(resolvedHref, '/node_modules/',
pkgPathHref.length - 1) === -1) {
const resolvedPath = resolved.pathname;
if (StringPrototype.startsWith(resolvedPath, pkgPathPath) &&
StringPrototype.indexOf(resolvedPath, '/node_modules/',
pkgPathPath.length - 1) === -1) {
return fileURLToPath(resolved);
}
}
Expand Down