Skip to content

Commit b5894a1

Browse files
Address CodeRabbit review: Fix path matching bug in resolveIgnorePattern
Fixed critical bug where absolutePattern.startsWith(cwd) could incorrectly match sibling directories with similar prefixes (e.g., '/project' matching '/projectdata'). Replaced string prefix check with path.relative() for proper path comparison. Now correctly checks if a path is under cwd by verifying the relative path doesn't start with '..'. All existing tests pass (82 tests total). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 266cb95 commit b5894a1

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

apps/jscpd/src/options.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-nocheck
2-
import {dirname, resolve, isAbsolute} from "path";
2+
import {dirname, resolve, isAbsolute, relative} from "path";
33
import {existsSync} from "fs";
44
import {Command} from 'commander';
55
import {readJSONSync} from 'fs-extra';
@@ -19,9 +19,10 @@ const resolveIgnorePattern = (configDir: string, pattern: string): string => {
1919
// instead of the config directory
2020
const absolutePattern = resolve(configDir, pattern);
2121
const cwd = process.cwd();
22-
// If the config is in a subdirectory of cwd, make pattern relative to cwd
23-
if (absolutePattern.startsWith(cwd)) {
24-
return absolutePattern.substring(cwd.length + 1);
22+
// If the config is in cwd or a subdirectory of cwd, make pattern relative to cwd
23+
const relativePath = relative(cwd, absolutePattern);
24+
if (!relativePath.startsWith('..')) {
25+
return relativePath;
2526
}
2627
// Otherwise return as absolute
2728
return absolutePattern;

0 commit comments

Comments
 (0)