From 99ced23d6951ffac46d70567cfdb286b21f9464b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 28 Sep 2021 06:43:43 +0000 Subject: [PATCH 1/4] fix: performance improvement --- index.js | 16 ++++++++++++++-- test/index.test.js | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) 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/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) { From 3abecee7811672982c0389754f0c819afea7451a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 29 Sep 2021 12:14:03 -0700 Subject: [PATCH 2/4] fixup! fix: performance improvement --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 801d046..2d896d3 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,6 @@ "pretest": "npm run lint", "test": "nyc mocha --async-only" }, - "dependencies": { - "is-glob": "^4.0.1" - }, "devDependencies": { "eslint": "^7.0.0", "eslint-config-gulp": "^5.0.0", @@ -50,5 +47,8 @@ "directory", "base", "wildcard" - ] + ], + "dependencies": { + "is-glob": "^4.0.3" + } } From 03e1b1f59504aa37d8a27c811a330ede68aeb6d0 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 29 Sep 2021 13:51:57 -0700 Subject: [PATCH 3/4] Update package.json --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index 2d896d3..6d32667 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,5 @@ "directory", "base", "wildcard" - ], - "dependencies": { - "is-glob": "^4.0.3" - } + ] } From 5e59da5fcf23ec3c321846c7ded84ca6d2d6a0fe Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 29 Sep 2021 13:53:30 -0700 Subject: [PATCH 4/4] fixup --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 6d32667..afc902a 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,9 @@ "pretest": "npm run lint", "test": "nyc mocha --async-only" }, + "dependencies": { + "is-glob": "^4.0.3" + }, "devDependencies": { "eslint": "^7.0.0", "eslint-config-gulp": "^5.0.0",