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

Pattern matching is too greedy #9

Open
johnhaley81 opened this issue Apr 7, 2015 · 2 comments
Open

Pattern matching is too greedy #9

johnhaley81 opened this issue Apr 7, 2015 · 2 comments

Comments

@johnhaley81
Copy link
Collaborator

var parser = require('gitignore-parser').compile('package');

parser.accepts('package.json'); // false

I would think that package.json should still be accepted since git CLI would not ignore that file with that .gitignore.

thomas-lebeau added a commit to thomas-lebeau/gitignore-parser that referenced this issue Sep 7, 2015
@thomas-lebeau thomas-lebeau mentioned this issue Sep 7, 2015
@kmalakoff
Copy link

I found the same thing. This logic is incorrect:

    accepts: function (input) {
      if (input[0] === '/') input = input.slice(1);
      return negatives[0].test(input) || !positives[0].test(input);
    },

It should be something like (but write tests to verify since I only tested my use case):

    accepts: function (input) {
      if (input[0] === '/') input = input.slice(1);
      if (positives[0].test(input)) return false;
      return negatives[0].test(input));
    },

I found it through doing something like and testing node_modules/backbone/package.json:

node_modules/
!node_modules/backbone/*

This library will list things in the backbone directory, but git would ignore the files based on the first condition before getting to the second one.

@kmalakoff
Copy link

I tried to port gitignore tests from libgit2 to to this module and stopped. The problem is that actually implementing gitignore to be fully compliant is very complex.

I've moved over to using the following module: https://github.com/kaelzhang/node-ignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants