Skip to content

Commit

Permalink
Removed "hasMagic" check before escaping paths. (#4931)
Browse files Browse the repository at this point in the history
* 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 <michael.allanson@gmail.com>
  • Loading branch information
theodab and m-allanson committed Sep 13, 2020
1 parent 89a530b commit 1dfd78b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/__tests__/fixtures/globs/a(b)/styles.css
@@ -0,0 +1 @@
a {}
1 change: 1 addition & 0 deletions lib/__tests__/standalone-globs.test.js
Expand Up @@ -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`,
Expand Down
12 changes: 5 additions & 7 deletions lib/standalone.js
Expand Up @@ -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;
Expand Down

0 comments on commit 1dfd78b

Please sign in to comment.