ggreer / the_silver_searcher

A code-searching tool similar to ack, but faster.

Home Page:http://geoff.greer.fm/ag/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

-L has false positives in certain files due to newlines

jmhodges-color opened this issue · comments

Probably related to #1494. This is with 2.2.0 on macOS 12.5.1 on an M1 MBP.

When a file's first line has a match, and is followed by 2 newlines, that file will still show up as not having a match when -L is provided.

It seems

$ printf "django\n\nokay" > foobar
$ ag  -L django foobar                                  
foobar
$ ag  -l django foobar                                  
foobar

That first foobar shouldn't be returned because there was, in fact, a line with django in it.

The same thing will happen if its just two newlines with not additional text (that is, printf "django\n\n" > foobar)

This turned up when grepping for files that didn't reference django but included Django migration files:

$ ag --py -L django my-django-project/
...
my-django-project/migrations/0001_do_something.py
...

$ cat my-django-project/migrations/0001_do_something.py
from django.db import migrations


def dothing(apps, schema_editor):
   foo

It seems to be the newlines are the problem

@jmhodges-color I was able to resolve my issue by building from source... you might give that a try.