From 7db1bdb0756e55fd14619e8ce31aa31b17b117fd Mon Sep 17 00:00:00 2001 From: Elan Shanker Date: Mon, 14 Nov 2016 12:03:49 -0500 Subject: [PATCH] feat: handle extglobs (parentheses) containing separators --- index.js | 2 +- test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c2b12c2..91a863e 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ module.exports = function globParent(str) { // remove path parts that are globby do {str = pathDirname.posix(str)} - while (isglob(str) || /(^|[^\\])[\{\[]/.test(str)); + while (isglob(str) || /(^|[^\\])([\{\[]|\([^\)]+$)/.test(str)); // remove escape chars and return result return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1'); diff --git a/test.js b/test.js index f85b9a2..fb9022a 100644 --- a/test.js +++ b/test.js @@ -94,6 +94,9 @@ describe('glob-parent', function() { assert.equal(gp('path/foo\\[a\\\/]/'), 'path/foo[a\\\/]'); assert.equal(gp('foo[a\\\/]'), '.'); assert.equal(gp('foo\\[a\\\/]'), 'foo[a\\\/]'); + assert.equal(gp('path/(foo/bar|baz)'), 'path'); + assert.equal(gp('path/(foo/bar|baz)/'), 'path'); + assert.equal(gp('path/\\(foo/bar|baz)/'), 'path/(foo/bar|baz)'); }); it('should handle nested braces', function() {