diff --git a/index.js b/index.js index 292d24f..0bd2a95 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,6 @@ var isWin32 = require('os').platform() === 'win32'; var slash = '/'; var backslash = /\\/g; -var globby = /(^|[^\\])([{[]|\([^)]+$)/; var escaped = /\\([!*?|[\](){}])/g; /** @@ -33,7 +32,7 @@ module.exports = function globParent(str, opts) { // remove path parts that are globby do { str = pathPosixDirname(str); - } while (isGlob(str) || globby.test(str)); + } while (isGlobby(str)); // remove escape chars and return result return str.replace(escaped, '$1'); @@ -61,3 +60,16 @@ function isEnclosure(str) { return str.slice(foundIndex + 1, -1).includes(slash); } + +function isGlobby(str) { + if (/\([^()]+$/.test(str)) { + return true; + } + if (str[0] === '{' || str[0] === '[') { + return true; + } + if (/[^\\][{[]/.test(str)) { + return true; + } + return isGlob(str); +} diff --git a/package.json b/package.json index 801d046..afc902a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "test": "nyc mocha --async-only" }, "dependencies": { - "is-glob": "^4.0.1" + "is-glob": "^4.0.3" }, "devDependencies": { "eslint": "^7.0.0", diff --git a/test/index.test.js b/test/index.test.js index 7f1ee15..5889412 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -242,6 +242,12 @@ describe('glob2base test patterns', function () { gp('('.repeat(500000)); done(); }); + + it("should finish in reasonable time for '/('.repeat(n) + ')'", function (done) { + this.timeout(1000); + gp('/('.repeat(500000) + ')'); + done(); + }); }); if (isWin32) {