Skip to content

Commit

Permalink
fix: unescape glob-escaped dirnames on output
Browse files Browse the repository at this point in the history
  • Loading branch information
es128 authored and phated committed Jan 27, 2021
1 parent cdbea5f commit 598c533
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ var pathDirname = require('path-dirname');
module.exports = function globParent(str) {
str += 'a'; // preserves full path in case of trailing path separator
do {str = pathDirname.posix(str)} while (isglob(str));
return str;
return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1');
};
14 changes: 7 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ describe('glob-parent', function() {
});

it('should respect escaped characters', function() {
assert.equal(gp('path/\\*\\*/subdir/foo.*'), 'path/\\*\\*/subdir');
assert.equal(gp('path/\\[\\*\\]/subdir/foo.*'), 'path/\\[\\*\\]/subdir');
assert.equal(gp('path/\\*\\*/subdir/foo.*'), 'path/**/subdir');
assert.equal(gp('path/\\[\\*\\]/subdir/foo.*'), 'path/[*]/subdir');
assert.equal(gp('path/\\*(a|b)/subdir/foo.*'), 'path');
assert.equal(gp('path/\\*/(a|b)/subdir/foo.*'), 'path/\\*');
assert.equal(gp('path/\\*\\(a\\|b\\)/subdir/foo.*'), 'path/\\*\\(a\\|b\\)/subdir');
assert.equal(gp('path/\\[foo bar\\]/subdir/foo.*'), 'path/\\[foo bar\\]/subdir');
assert.equal(gp('path/\\[bar]/'), 'path/\\[bar]');
assert.equal(gp('path/foo \\[bar]/'), 'path/foo \\[bar]');
assert.equal(gp('path/\\*/(a|b)/subdir/foo.*'), 'path/*');
assert.equal(gp('path/\\*\\(a\\|b\\)/subdir/foo.*'), 'path/*(a|b)/subdir');
assert.equal(gp('path/\\[foo bar\\]/subdir/foo.*'), 'path/[foo bar]/subdir');
assert.equal(gp('path/\\[bar]/'), 'path/[bar]');
assert.equal(gp('path/foo \\[bar]/'), 'path/foo [bar]');
});

it('should return parent dirname from non-glob paths', function() {
Expand Down

0 comments on commit 598c533

Please sign in to comment.