Skip to content

Commit efa7459

Browse files
committed
fix(include-parser): infinite recursion or out-of-memory with
symlinks/large projects
1 parent bf655d1 commit efa7459

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

src/parser-includes.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,16 @@ export function resolveSemanticVersionRange (range: string, gitTags: string[]) {
362362
}
363363

364364
export function resolveIncludeLocal (pattern: string, cwd: string) {
365-
const repoFiles = ParserIncludes.memoLocalRepoFiles(cwd);
366-
367365
if (!pattern.startsWith("/")) pattern = `/${pattern}`; // Ensure pattern starts with `/`
368366
pattern = `${cwd}${pattern}`;
369367

370-
// escape all special regex metacharacters
371-
pattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
372-
373-
// `**` matches anything
374-
const anything = ".*?";
375-
pattern = pattern.replace(/\\\*\\\*/g, anything);
376-
377-
// `*` matches anything except for `/`
378-
const anything_but_not_slash = "([^/])*?";
379-
pattern = pattern.replace(/\\\*/g, anything_but_not_slash);
368+
if (!pattern.includes("*")) {
369+
if (fs.existsSync(pattern)) {
370+
return [pattern];
371+
} else {
372+
return [];
373+
}
374+
}
380375

381-
const re2js = RE2JS.compile(`^${pattern}`);
382-
return repoFiles.filter((f: any) => re2js.matches(f));
376+
return globby.sync(pattern, {dot: true, gitignore: true});
383377
}

0 commit comments

Comments
 (0)