From 99ec9fecc60ee488ded20a94dd4f18b4f55c4ccf Mon Sep 17 00:00:00 2001 From: Elan Shanker Date: Tue, 18 Oct 2016 20:10:46 -0400 Subject: [PATCH] fix: trailing escaped square brackets --- index.js | 2 +- test.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6a18407..c141b1c 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ var pathDirname = require('path-dirname'); module.exports = function globParent(str) { // replace braces/brackets sections with * str = str.replace(/(^|[^\\])(\{([^{}]*?)}|\[([^\[\]]*?)\])/g, '$1*'); - if (/[\}\}]$/.test(str)) str += '/'; + if (/[\}\]]$/.test(str)) str += '/'; // preserves full path in case of trailing path separator str += 'a'; diff --git a/test.js b/test.js index 18c110e..ac4bd1d 100644 --- a/test.js +++ b/test.js @@ -79,6 +79,8 @@ describe('glob-parent', function() { assert.equal(gp('\\{,/,bar/baz,qux\\}'), '{,/,bar/baz,qux}'); assert.equal(gp('path/foo[a\\\/]/'), 'path'); assert.equal(gp('path/foo\\[a\\\/]/'), 'path/foo[a\\\/]'); + assert.equal(gp('foo[a\\\/]'), '.'); + assert.equal(gp('foo\\[a\\\/]'), 'foo[a\\\/]'); }); it('should return parent dirname from non-glob paths', function() {