diff --git a/index.js b/index.js index 268fc47..a05c000 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,19 @@ module.exports = function(glob, options) { glob += '/'; } + // resolve '..' parts in path + glob = glob.split('/').reduce(function(parts, part) { + if (part === '..') { + if (parts.pop() === '' && !parts.length) { + parts.push(''); + } + } else { + parts.push(part); + } + + return parts; + }, []).join('/'); + // re-add leading `!` if it was removed return ing.negated ? '!' + glob : glob; }; diff --git a/package.json b/package.json index 762ab5c..f53f925 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "to-absolute-glob", "description": "Make a glob pattern absolute, ensuring that negative globs and patterns with trailing slashes are correctly handled.", - "version": "2.0.2", + "version": "2.0.3", "homepage": "https://github.com/jonschlinkert/to-absolute-glob", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "contributors": [ diff --git a/test.js b/test.js index 4ecbb08..edc6198 100644 --- a/test.js +++ b/test.js @@ -76,6 +76,11 @@ describe('resolve', function () { assert.equal(actual, unixify(path.resolve('/a/*.js'))); }); + it('should resolve relative parent dirs', function () { + actual = resolve('/../../a/b/c/../d/../../e/f/g/../*', {root: '/'}); + assert.equal(actual, unixify(path.resolve('/a/e/f/*'))); + }); + it('should make a glob absolute from a negative root path', function () { actual = resolve('!/a/*.js', {root: 'foo'}); assert.equal(actual, '!' + unixify(path.resolve('foo/a/*.js')));