From 4c80b02d687d642e5125f58d9ff56983fe753dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Miserey?= Date: Mon, 29 May 2017 20:49:57 +0200 Subject: [PATCH] Fix detection of parent directory in ModuleScopePlugin (#2405) * Fix detection of parent directory * Correct parent directory detection fix Add windows specific path and extend to issuer path --- packages/react-dev-utils/ModuleScopePlugin.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/react-dev-utils/ModuleScopePlugin.js b/packages/react-dev-utils/ModuleScopePlugin.js index fd70a2f40..adc9bdcba 100644 --- a/packages/react-dev-utils/ModuleScopePlugin.js +++ b/packages/react-dev-utils/ModuleScopePlugin.js @@ -37,7 +37,10 @@ class ModuleScopePlugin { // Maybe an indexOf === 0 would be better? const relative = path.relative(appSrc, request.context.issuer); // If it's not in src/ or a subdirectory, not our request! - if (relative[0] === '.') { + if ( + relative.startsWith('../') || + relative.startsWith('..\\') + ) { return callback(); } // Find path from src to the requested file @@ -49,7 +52,10 @@ class ModuleScopePlugin { ) ); // Error if in a parent directory of src/ - if (requestRelative[0] === '.') { + if ( + requestRelative.startsWith('../') || + requestRelative.startsWith('..\\') + ) { callback( new Error( `You attempted to import ${chalk.cyan(request.__innerRequest_request)} which falls outside of the project ${chalk.cyan('src/')} directory. ` +