Skip to content

Commit

Permalink
fix: trailing escaped square brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
es128 authored and phated committed Jan 27, 2021
1 parent 8cfb0ba commit 99ec9fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 99ec9fe

Please sign in to comment.