Skip to content

Commit

Permalink
strip leading ./ from ignore patterns
Browse files Browse the repository at this point in the history
fix: #570
  • Loading branch information
isaacs committed Mar 28, 2024
1 parent 7e927b2 commit e775a78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export class Ignore implements IgnoreLike {
if (!parsed || !globParts) {
throw new Error('invalid pattern object')
}
// strip off leading ./ portions
// https://github.com/isaacs/node-glob/issues/570
while (parsed[0] === '.' && globParts[0] === '.') {
parsed.shift()
globParts.shift()
}
/* c8 ignore stop */
const p = new Pattern(parsed, globParts, 0, platform)
const m = new Minimatch(p.globString(), mmopts)
Expand Down
13 changes: 13 additions & 0 deletions test/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Case = [
expect: string[],
optOrCwd?: GlobOptions | string | undefined
]

const cases: Case[] = [
[
'*',
Expand Down Expand Up @@ -336,6 +337,18 @@ const cases: Case[] = [
(process.cwd() + '/a/x/**').split(sep).join('/'),
j(['a/z/.y/b']),
],
[
'./*',
'{./,c}b',
j(['abcdef', 'abcfed', 'bc', 'c', 'symlink', 'x', 'z']),
'a',
],
[
'./*',
'./c/../b',
j(['abcdef', 'abcfed', 'bc', 'c', 'cb', 'symlink', 'x', 'z']),
'a',
],
]

for (const c of cases) {
Expand Down

0 comments on commit e775a78

Please sign in to comment.