From 95ff43248de7f1a2f879bc22f62a0240e23da5a9 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Thu, 11 Apr 2019 17:22:42 -0700 Subject: [PATCH] fix: deep match with higher level siblings --- index.js | 2 +- sync.js | 2 +- test/fixtures/deep/a/e | 0 test/fixtures/deep/b/c/d | 0 test/glob.js | 8 ++++++++ 5 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/deep/a/e create mode 100644 test/fixtures/deep/b/c/d diff --git a/index.js b/index.js index 0c1a746..b57c2ad 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,7 @@ async function walk(output, prefix, lexer, opts, dirname='', level=0) { if (rgx && !rgx.test(file)) continue; !filesOnly && isMatch && output.push(join(prefix, relpath)); - await walk(output, prefix, lexer, opts, relpath, rgx && rgx.toString() !== lexer.globstar && ++level); + await walk(output, prefix, lexer, opts, relpath, rgx && rgx.toString() !== lexer.globstar && level + 1); } } diff --git a/sync.js b/sync.js index 17ba784..8f16dc9 100644 --- a/sync.js +++ b/sync.js @@ -33,7 +33,7 @@ function walk(output, prefix, lexer, opts, dirname='', level=0) { if (rgx && !rgx.test(file)) continue; !filesOnly && isMatch && output.push(join(prefix, relpath)); - walk(output, prefix, lexer, opts, relpath, rgx && rgx.toString() !== lexer.globstar && ++level); + walk(output, prefix, lexer, opts, relpath, rgx && rgx.toString() !== lexer.globstar && level + 1); } } diff --git a/test/fixtures/deep/a/e b/test/fixtures/deep/a/e new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/deep/b/c/d b/test/fixtures/deep/b/c/d new file mode 100644 index 0000000..e69de29 diff --git a/test/glob.js b/test/glob.js index 892c0ba..30b4276 100644 --- a/test/glob.js +++ b/test/glob.js @@ -218,3 +218,11 @@ test('glob: options.filesOnly (without glob)', async t => { 'test/fixtures/one', ]); }); + +test('glob: deep match with higher level siblings', async t => { + t.plan(1); + + await isMatch(t, 'test/fixtures/deep/*/c/d', {}, [ + 'test/fixtures/deep/b/c/d' + ]); +});