Skip to content

Commit

Permalink
fix: inifite loop when passing certain paths to findFile (#1430)
Browse files Browse the repository at this point in the history
`findFile` assumes the first parameter is always a filename. If a path
is passed, the root directory is never reached and thus not terminate
the loop.
  • Loading branch information
tido64 authored May 22, 2023
1 parent fd664ec commit bef8c06
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions scripts/validate-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ const BUILD_PROPS = [
* @returns {string | undefined}
*/
function findFile(file, startDir = process.cwd()) {
let candidate = path.join(startDir, file);
let currentDir = startDir;
let candidate = path.join(currentDir, file);
while (!fs.existsSync(candidate)) {
const cwd = path.dirname(candidate);
const parent = path.dirname(cwd);
if (parent === cwd) {
const nextDir = path.dirname(currentDir);
if (nextDir === currentDir) {
return undefined;
}

candidate = path.join(parent, file);
currentDir = nextDir;
candidate = path.join(currentDir, file);
}

return candidate;
}

Expand Down

0 comments on commit bef8c06

Please sign in to comment.