Skip to content

Commit

Permalink
Protect against roots that are contained within other roots
Browse files Browse the repository at this point in the history
Summary:
For example, I could have a root named `random` and another root named `randomColor`.
A child of `randomColor` would **incorrectly** pass as a descendant of `random`.

So this commit changes `isDescendant` to do 2 things:
- check for exact matches (eg: the path is a root)
- call `startsWith` like before, but append `path.sep` to avoid false positives
Closes #9831

Differential Revision: D3864968

fbshipit-source-id: 7fe04913579aa0741840fc925216283304ae3433
  • Loading branch information
aleclarson authored and Facebook Github Bot 9 committed Sep 14, 2016
1 parent 3dac49a commit d4dff25
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function watchmanRecReadDir(roots, {ignore, fileWatcher, exts}) {
}

function isDescendant(root, child) {
return child.startsWith(root);
return root === child || child.startsWith(root + path.sep);
}

module.exports = watchmanRecReadDir;
2 changes: 1 addition & 1 deletion packager/react-packager/src/node-haste/fastfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function makeReadCallback(fd, predicate, callback) {
}

function isDescendant(root, child) {
return child.startsWith(root);
return root === child || child.startsWith(root + path.sep);
}

module.exports = Fastfs;

0 comments on commit d4dff25

Please sign in to comment.