fix: prevent RangeError in GitIgnoreParser for root paths (#3417)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
parent
fe00686c58
commit
c0bfa388c5
|
@ -161,6 +161,21 @@ src/*.tmp
|
||||||
expect(parser.isIgnored('node_modules\\package')).toBe(true);
|
expect(parser.isIgnored('node_modules\\package')).toBe(true);
|
||||||
expect(parser.isIgnored('src\\temp.tmp')).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', () => {
|
describe('getIgnoredPatterns', () => {
|
||||||
|
|
|
@ -61,7 +61,12 @@ export class GitIgnoreParser implements GitIgnoreFilter {
|
||||||
? path.relative(this.projectRoot, filePath)
|
? path.relative(this.projectRoot, filePath)
|
||||||
: filePath;
|
: filePath;
|
||||||
|
|
||||||
if (relativePath === '' || relativePath.startsWith('..')) {
|
if (
|
||||||
|
relativePath === '' ||
|
||||||
|
relativePath.startsWith('..') ||
|
||||||
|
relativePath === '/' ||
|
||||||
|
relativePath.startsWith('/')
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue