From bc0c34967ee74e9ae223665e7383e5eb8e273365 Mon Sep 17 00:00:00 2001 From: aleclarsoniv Date: Wed, 14 Sep 2016 13:38:15 -0700 Subject: [PATCH] Protect against roots that are contained within other roots 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 https://github.com/facebook/react-native/pull/9831 Differential Revision: D3864968 fbshipit-source-id: 7fe04913579aa0741840fc925216283304ae3433 --- react-packager/src/node-haste/crawlers/watchman.js | 2 +- react-packager/src/node-haste/fastfs.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/react-packager/src/node-haste/crawlers/watchman.js b/react-packager/src/node-haste/crawlers/watchman.js index 1b29634f..284fe673 100644 --- a/react-packager/src/node-haste/crawlers/watchman.js +++ b/react-packager/src/node-haste/crawlers/watchman.js @@ -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; diff --git a/react-packager/src/node-haste/fastfs.js b/react-packager/src/node-haste/fastfs.js index 56c6f6a5..ad25c1d5 100644 --- a/react-packager/src/node-haste/fastfs.js +++ b/react-packager/src/node-haste/fastfs.js @@ -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;