Skip to content

Commit

Permalink
fix(filters/deep): fix a problem with matching for patterns with lead…
Browse files Browse the repository at this point in the history
…ing dot
  • Loading branch information
mrmlnc committed Feb 21, 2020
1 parent 78c7780 commit 2466aea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/providers/filters/deep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,24 @@ describe('Providers → Filters → Deep', () => {
});

it('should return `false` when an entry starts with "./" and does not match to the positive pattern', () => {
const filter = getFilter('.', ['non-root/directory'], []);
const filter = getFilter('.', ['non-root/*'], []);
const entry = tests.entry.builder().path('./root').directory().build();

const actual = filter(entry);

assert.ok(!actual);
});

it('should return `true` when the positive pattern does not match, but the `baseNameMatch` is enabled', () => {
it('should return `true` when an entry match to the positive pattern with leading dot', () => {
const filter = getFilter('.', ['./root/*'], []);
const entry = tests.entry.builder().path('./root').directory().build();

const actual = filter(entry);

assert.ok(actual);
});

it('should return `true` when the positive pattern does not match by level, but the `baseNameMatch` is enabled', () => {
const filter = getFilter('.', ['*'], [], { baseNameMatch: true });
const entry = tests.entry.builder().path('root/directory').directory().build();

Expand Down
4 changes: 3 additions & 1 deletion src/providers/filters/deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default class DeepFilter {
}

private _isSkippedByPositivePatterns(entry: Entry, matcher: PartialMatcher): boolean {
return !this._settings.baseNameMatch && !matcher.match(entry.path);
const filepath = entry.path.replace(/^\.[/\\]/, '');

return !this._settings.baseNameMatch && !matcher.match(filepath);
}

private _isSkippedByNegativePatterns(entry: Entry, negativeRe: PatternRe[]): boolean {
Expand Down

0 comments on commit 2466aea

Please sign in to comment.