From e775a784fd7ab20a3d06a9e0a6c52ee60988cbc5 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 28 Mar 2024 09:13:12 -0700 Subject: [PATCH] strip leading ./ from ignore patterns fix: https://github.com/isaacs/node-glob/issues/570 --- src/ignore.ts | 6 ++++++ test/ignore.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/ignore.ts b/src/ignore.ts index 61104c51..d5618194 100644 --- a/src/ignore.ts +++ b/src/ignore.ts @@ -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) diff --git a/test/ignore.ts b/test/ignore.ts index c1da0ba4..26865f6b 100644 --- a/test/ignore.ts +++ b/test/ignore.ts @@ -21,6 +21,7 @@ type Case = [ expect: string[], optOrCwd?: GlobOptions | string | undefined ] + const cases: Case[] = [ [ '*', @@ -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) {