Skip to content

Commit d96a7d9

Browse files
committed
fix: Check negative patterns before trimming
1 parent f346d01 commit d96a7d9

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ module.exports = function(glob, options) {
2525
rootDir = escape(rootDir);
2626
}
2727

28+
// store last character before glob is modified
29+
var suffix = glob.slice(-1);
30+
31+
// check to see if glob is negated (and not a leading negated-extglob)
32+
var ing = isNegated(glob);
33+
glob = ing.pattern;
34+
2835
// trim starting ./ from glob patterns
2936
if (glob.slice(0, 2) === './') {
3037
glob = glob.slice(2);
@@ -35,13 +42,6 @@ module.exports = function(glob, options) {
3542
glob = '';
3643
}
3744

38-
// store last character before glob is modified
39-
var suffix = glob.slice(-1);
40-
41-
// check to see if glob is negated (and not a leading negated-extglob)
42-
var ing = isNegated(glob);
43-
glob = ing.pattern;
44-
4545
// make glob absolute
4646
if (rootDir && glob.charAt(0) === '/') {
4747
glob = join(rootDir, glob);

test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ describe('resolve', function() {
4545
assert.equal(actual, '!' + unixify(path.resolve('a/*.js')));
4646
});
4747

48+
it('should make a negative glob (starting with `./`) absolute', function() {
49+
actual = resolve('!./a/*.js');
50+
assert.equal(actual, '!' + unixify(path.resolve('a/*.js')));
51+
});
52+
53+
it('should make a negative glob (just `./`) absolute', function() {
54+
actual = resolve('!./');
55+
assert.equal(actual, '!' + unixify(path.resolve('.')) + '/');
56+
});
57+
58+
it('should make a negative glob (just `.`) absolute', function() {
59+
actual = resolve('!.');
60+
assert.equal(actual, '!' + unixify(path.resolve('.')));
61+
});
62+
4863
it('should make a negative extglob absolute', function() {
4964
actual = resolve('!(foo)');
5065
assert.equal(actual, unixify(path.resolve('!(foo)')));

0 commit comments

Comments
 (0)