Skip to content

Commit

Permalink
New approach to braces/brackets handling
Browse files Browse the repository at this point in the history
  • Loading branch information
es128 committed Oct 19, 2016
1 parent 1c5ac28 commit e5c5313
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -5,15 +5,15 @@ var isglob = require('is-glob');
var pathDirname = require('path-dirname');

module.exports = function globParent(str) {
// replace braces/brackets sections with *
str = str.replace(/(^|[^\\])(\{([^{}]*?)}|\[([^\[\]]*?)\])/g, '$1*');
if (/[\}\]]$/.test(str)) str += '/';
// special case for strings ending in enclosure containing path separator
if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/';

// preserves full path in case of trailing path separator
str += 'a';

// remove path parts that are globby
do {str = pathDirname.posix(str)} while (isglob(str));
do {str = pathDirname.posix(str)}
while (isglob(str) || /(^|[^\\])[\{\[]/.test(str));

// remove escape chars and return result
return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1');
Expand Down

0 comments on commit e5c5313

Please sign in to comment.