From 6d484e847b62aa0829641f25a76dcc89b0840d44 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Wed, 9 May 2018 11:26:55 +0200 Subject: [PATCH] [FIX] AbstractAdapter: Fix normalization of globstar Matched index was off by one --- lib/Resource.js | 4 ++-- lib/adapters/AbstractAdapter.js | 2 +- test/lib/glob.js | 14 +++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/Resource.js b/lib/Resource.js index 2b4dc662..e2dda785 100644 --- a/lib/Resource.js +++ b/lib/Resource.js @@ -78,7 +78,7 @@ class Resource { } else if (this._createStream || this._stream) { resolve(this._getBufferFromStream()); } else { - reject(new Error(`Resource ${this._name} has no content`)); + reject(new Error(`Resource ${this._path} has no content`)); } }); } @@ -128,7 +128,7 @@ class Resource { } else if (this._createStream || this._stream) { return this._getStream(); } else { - throw new Error(`Resource ${this._name} has no content`); + throw new Error(`Resource ${this._path} has no content`); } } diff --git a/lib/adapters/AbstractAdapter.js b/lib/adapters/AbstractAdapter.js index b5a05dc6..5825145f 100644 --- a/lib/adapters/AbstractAdapter.js +++ b/lib/adapters/AbstractAdapter.js @@ -77,7 +77,7 @@ class AbstractAdapter extends AbstractReaderWriter { continue; } } else if (globPart === minimatch.GLOBSTAR) { - return i > 0 ? i - 1 : i; + return i; } else { // Regex if (!globPart.test(basePathPart)) { return -42; diff --git a/test/lib/glob.js b/test/lib/glob.js index ef2247b6..96a9646d 100644 --- a/test/lib/glob.js +++ b/test/lib/glob.js @@ -57,7 +57,7 @@ test("GLOB all from root only", (t) => { }); }); -test("GLOB all with virtual path included", (t) => { +test("GLOB all with virtual base path fully matching", (t) => { t.plan(1); return t.context.readerWriter.filesystem.byGlob("/test-resources/**/*.*") .then((resources) => { @@ -65,6 +65,18 @@ test("GLOB all with virtual path included", (t) => { }); }); +test("GLOB with virtual base path partially matching", (t) => { + t.plan(1); + const adapter = new FsAdapter({ + fsBasePath: "./test/fixtures/glob/application.a", + virBasePath: "/test-resources/application/a/" + }); + return adapter.byGlob("/test-resources/**/*.*") + .then((resources) => { + t.deepEqual(resources.length, 4, "Found all resources"); + }); +}); + test("Check for unstable order of GLOB result", (t) => { t.plan(1); return t.context.readerWriter.filesystem.byGlob("/**/*.*")