Skip to content

Commit

Permalink
Fix detection of parent directory in ModuleScopePlugin (#2405)
Browse files Browse the repository at this point in the history
* Fix detection of parent directory

* Correct parent directory detection fix

Add windows specific path and extend to issuer path
  • Loading branch information
Frédéric Miserey authored and gaearon committed May 29, 2017
1 parent 32f82c0 commit bcf398d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/react-dev-utils/ModuleScopePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. ` +
Expand Down

0 comments on commit bcf398d

Please sign in to comment.