Skip to content

Commit

Permalink
fix: Check negative patterns before trimming (#1)
Browse files Browse the repository at this point in the history
chore: Revert the mocha change to test on old node
  • Loading branch information
phated committed Jan 3, 2023
1 parent f346d01 commit 1faa5dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ module.exports = function(glob, options) {
rootDir = escape(rootDir);
}

// store last character before glob is modified
var suffix = glob.slice(-1);

// check to see if glob is negated (and not a leading negated-extglob)
var ing = isNegated(glob);
glob = ing.pattern;

// trim starting ./ from glob patterns
if (glob.slice(0, 2) === './') {
glob = glob.slice(2);
Expand All @@ -35,13 +42,6 @@ module.exports = function(glob, options) {
glob = '';
}

// store last character before glob is modified
var suffix = glob.slice(-1);

// check to see if glob is negated (and not a leading negated-extglob)
var ing = isNegated(glob);
glob = ing.pattern;

// make glob absolute
if (rootDir && glob.charAt(0) === '/') {
glob = join(rootDir, glob);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"gulp-format-md": "^2.0.0",
"mocha": "^10.1.0"
"mocha": "^3.0.2"
},
"keywords": [
"absolute",
Expand Down
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ describe('resolve', function() {
assert.equal(actual, '!' + unixify(path.resolve('a/*.js')));
});

it('should make a negative glob (starting with `./`) absolute', function() {
actual = resolve('!./a/*.js');
assert.equal(actual, '!' + unixify(path.resolve('a/*.js')));
});

it('should make a negative glob (just `./`) absolute', function() {
actual = resolve('!./');
assert.equal(actual, '!' + unixify(path.resolve('.')) + '/');
});

it('should make a negative glob (just `.`) absolute', function() {
actual = resolve('!.');
assert.equal(actual, '!' + unixify(path.resolve('.')));
});

it('should make a negative extglob absolute', function() {
actual = resolve('!(foo)');
assert.equal(actual, unixify(path.resolve('!(foo)')));
Expand Down

0 comments on commit 1faa5dc

Please sign in to comment.