Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down