From d9bedd4c34f7290a5a44d2bae7fd2a4bdb55c1fc Mon Sep 17 00:00:00 2001 From: Theodore Abshire Date: Wed, 2 Sep 2020 14:14:22 -0700 Subject: [PATCH 1/3] Removed "hasMagic" check before escaping paths. Globby's "hasMagic" function, which is meant to detect if a path contains globbing characters, notably does not detect paths that contain matched parentheses, unless those matched parentheses have extra globbing characters attached to them. This is a problem because globby requires matches parentheses to be escaped, if they are part of the literal path. This changes the part of the code that escapes paths that literally exist to not check "hasMagic" first, to get around that oversight. --- lib/standalone.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/standalone.js b/lib/standalone.js index e92d9c1946..ff85e60ce0 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -172,14 +172,12 @@ module.exports = function (options) { } fileList = fileList.map((entry) => { - if (globby.hasMagic(entry)) { - const cwd = _.get(globbyOptions, 'cwd', process.cwd()); - const absolutePath = !path.isAbsolute(entry) ? path.join(cwd, entry) : path.normalize(entry); + const cwd = _.get(globbyOptions, 'cwd', process.cwd()); + const absolutePath = !path.isAbsolute(entry) ? path.join(cwd, entry) : path.normalize(entry); - if (fs.existsSync(absolutePath)) { - // This glob-like path points to a file. Return an escaped path to avoid globbing - return fastGlob.escapePath(entry); - } + if (fs.existsSync(absolutePath)) { + // This glob-like path points to a file. Return an escaped path to avoid globbing + return fastGlob.escapePath(entry); } return entry; From 9b9b5732844a4156aa79856c1d9c8d1640080e45 Mon Sep 17 00:00:00 2001 From: m-allanson Date: Thu, 3 Sep 2020 12:24:37 +0100 Subject: [PATCH 2/3] Add test --- lib/__tests__/fixtures/globs/a(b)/styles.css | 1 + lib/__tests__/standalone-globs.test.js | 1 + 2 files changed, 2 insertions(+) create mode 100644 lib/__tests__/fixtures/globs/a(b)/styles.css diff --git a/lib/__tests__/fixtures/globs/a(b)/styles.css b/lib/__tests__/fixtures/globs/a(b)/styles.css new file mode 100644 index 0000000000..077f6dd7c0 --- /dev/null +++ b/lib/__tests__/fixtures/globs/a(b)/styles.css @@ -0,0 +1 @@ +a {} diff --git a/lib/__tests__/standalone-globs.test.js b/lib/__tests__/standalone-globs.test.js index 2f3f486287..0d9d2c8255 100644 --- a/lib/__tests__/standalone-globs.test.js +++ b/lib/__tests__/standalone-globs.test.js @@ -21,6 +21,7 @@ describe('standalone globbing', () => { // ref https://github.com/micromatch/micromatch#matching-features const fixtureDirs = [ `[digit]/not-digits`, + `a(b)`, `with spaces`, `extglob!(s)`, `got!negate/negate`, From 941a097114756bf2bd8a4d4dff1f659bcc520eb4 Mon Sep 17 00:00:00 2001 From: m-allanson Date: Thu, 3 Sep 2020 12:25:01 +0100 Subject: [PATCH 3/3] Update comment --- lib/standalone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/standalone.js b/lib/standalone.js index ff85e60ce0..0f5b46a2dc 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -176,7 +176,7 @@ module.exports = function (options) { const absolutePath = !path.isAbsolute(entry) ? path.join(cwd, entry) : path.normalize(entry); if (fs.existsSync(absolutePath)) { - // This glob-like path points to a file. Return an escaped path to avoid globbing + // This path points to a file. Return an escaped path to avoid globbing return fastGlob.escapePath(entry); }