Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check negative patterns before trimming #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been reverted since we didn't drop old node support in the major.

},
"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