Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core/src/utils/gitIgnoreParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ src/*.tmp
expect(parser.isIgnored(outsidePath)).toBe(false);
});

it('should still evaluate files whose names start with two dots', async () => {
await createTestFile('.gitignore', '..secret.log');

expect(parser.isIgnored('..secret.log')).toBe(true);
});

it('should handle relative paths correctly', () => {
expect(parser.isIgnored(path.join('node_modules', 'some-package'))).toBe(
true,
Expand Down
11 changes: 5 additions & 6 deletions packages/core/src/utils/gitIgnoreParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import ignore from 'ignore';
import { isPathWithinRoot } from './workspaceContext.js';

export interface GitIgnoreFilter {
isIgnored(filePath: string): boolean;
Expand Down Expand Up @@ -102,16 +103,14 @@ export class GitIgnoreParser implements GitIgnoreFilter {
return false;
}

const absoluteFilePath = path.resolve(this.projectRoot, filePath);
if (!absoluteFilePath.startsWith(this.projectRoot)) {
return false;
}

try {
const resolved = path.resolve(this.projectRoot, filePath);
const relativePath = path.relative(this.projectRoot, resolved);

if (relativePath === '' || relativePath.startsWith('..')) {
if (
relativePath === '' ||
!isPathWithinRoot(resolved, this.projectRoot)
) {
return false;
}

Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/utils/qwenIgnoreParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ describe('QwenIgnoreParser', () => {
false,
);
});

it('should still evaluate files whose names start with two dots', async () => {
await createTestFile('.qwenignore', '..secret.log');

const parser = new QwenIgnoreParser(projectRoot);

expect(parser.isIgnored('..secret.log')).toBe(true);
});

it('should not evaluate paths outside the project root', () => {
const parser = new QwenIgnoreParser(projectRoot);

expect(parser.isIgnored(path.join('..', '..secret.log'))).toBe(false);
});
});

describe('when .qwenignore does not exist', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/qwenIgnoreParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import ignore from 'ignore';
import { isPathWithinRoot } from './workspaceContext.js';

export interface QwenIgnoreFilter {
isIgnored(filePath: string): boolean;
Expand Down Expand Up @@ -61,7 +62,7 @@ export class QwenIgnoreParser implements QwenIgnoreFilter {
const resolved = path.resolve(this.projectRoot, filePath);
const relativePath = path.relative(this.projectRoot, resolved);

if (relativePath === '' || relativePath.startsWith('..')) {
if (relativePath === '' || !isPathWithinRoot(resolved, this.projectRoot)) {
return false;
}

Expand Down
Loading