diff options
| author | osbornesec <[email protected]> | 2025-07-20 02:12:53 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-20 07:12:53 +0000 |
| commit | c0bfa388c571342265915f8de888a43190c82759 (patch) | |
| tree | ef3f069a4876a17f946a023bbf1356042668c549 /packages/core/src | |
| parent | fe00686c58421ae7d9a60bddf38deda35591709b (diff) | |
fix: prevent RangeError in GitIgnoreParser for root paths (#3417)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/core/src')
| -rw-r--r-- | packages/core/src/utils/gitIgnoreParser.test.ts | 15 | ||||
| -rw-r--r-- | packages/core/src/utils/gitIgnoreParser.ts | 7 |
2 files changed, 21 insertions, 1 deletions
diff --git a/packages/core/src/utils/gitIgnoreParser.test.ts b/packages/core/src/utils/gitIgnoreParser.test.ts index f58d50be..d94a7bfa 100644 --- a/packages/core/src/utils/gitIgnoreParser.test.ts +++ b/packages/core/src/utils/gitIgnoreParser.test.ts @@ -161,6 +161,21 @@ src/*.tmp expect(parser.isIgnored('node_modules\\package')).toBe(true); expect(parser.isIgnored('src\\temp.tmp')).toBe(true); }); + + it('should handle root path "/" without throwing error', () => { + expect(() => parser.isIgnored('/')).not.toThrow(); + expect(parser.isIgnored('/')).toBe(false); + }); + + it('should handle absolute-like paths without throwing error', () => { + expect(() => parser.isIgnored('/some/path')).not.toThrow(); + expect(parser.isIgnored('/some/path')).toBe(false); + }); + + it('should handle paths that start with forward slash', () => { + expect(() => parser.isIgnored('/node_modules')).not.toThrow(); + expect(parser.isIgnored('/node_modules')).toBe(false); + }); }); describe('getIgnoredPatterns', () => { diff --git a/packages/core/src/utils/gitIgnoreParser.ts b/packages/core/src/utils/gitIgnoreParser.ts index 37041272..50018bb7 100644 --- a/packages/core/src/utils/gitIgnoreParser.ts +++ b/packages/core/src/utils/gitIgnoreParser.ts @@ -61,7 +61,12 @@ export class GitIgnoreParser implements GitIgnoreFilter { ? path.relative(this.projectRoot, filePath) : filePath; - if (relativePath === '' || relativePath.startsWith('..')) { + if ( + relativePath === '' || + relativePath.startsWith('..') || + relativePath === '/' || + relativePath.startsWith('/') + ) { return false; } |
