From 1dfd78bb61c3286f71441eea22e392de25a450df Mon Sep 17 00:00:00 2001 From: theodab Date: Sun, 13 Sep 2020 03:47:59 -0700 Subject: [PATCH] Removed "hasMagic" check before escaping paths. (#4931) * 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. * Add test * Update comment Co-authored-by: m-allanson --- lib/__tests__/fixtures/globs/a(b)/styles.css | 1 + lib/__tests__/standalone-globs.test.js | 1 + lib/standalone.js | 12 +++++------- 3 files changed, 7 insertions(+), 7 deletions(-) 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`, diff --git a/lib/standalone.js b/lib/standalone.js index e92d9c1946..0f5b46a2dc 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 path points to a file. Return an escaped path to avoid globbing + return fastGlob.escapePath(entry); } return entry;