Skip to content

Commit

Permalink
Fix findConfigFrom directory traversal for non-Unix OSes (#20)
Browse files Browse the repository at this point in the history
* Robustly determine parent directory.

* prevPath is clearer than oldPath
  • Loading branch information
jadoc authored Mar 5, 2023
1 parent 70f58ec commit 3a632be
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/configGenerator/configLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function findConfigFrom(path: string) {
);
assert(await isDir(path), '`path` must be a directory');

let prevPath = null;
let currentPath = resolve(path);
do {
try {
Expand All @@ -35,8 +36,9 @@ export async function findConfigFrom(path: string) {
}
}

currentPath = dirname(currentPath);
} while (currentPath !== '.' && currentPath !== '/');
prevPath = currentPath;
currentPath = dirname(prevPath);
} while (currentPath != prevPath);

throw new Error(`Unable to locate ${CONFIG_FILENAME} on the current path`);
}

0 comments on commit 3a632be

Please sign in to comment.