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

yaml start of document causes last line false negative with -L

james-powis opened this issue · comments

The yaml start of document --- causes the last line of the document to not evaluate correctly with -L but does so with -l

Without document start, everything works as expected:

(venv)  /tmp/ echo "needle: true" > /tmp/haystack
(venv)  /tmp/ echo "Present: $(ag -l needle /tmp/haystack)      Not_Present: $(ag -L needle /tmp/haystack)"
Present: /tmp/haystack      Not_Present:

With document start, we get Schrödinger's Search Result (it both exists and does not exist):

(venv)  /tmp/ echo "---\nneedle: true" > /tmp/haystack
(venv)  /tmp/ echo "Present: $(ag -l needle /tmp/haystack)      Not_Present: $(ag -L needle /tmp/haystack)"
Present: /tmp/haystack      Not_Present: /tmp/haystack

Having an empty line at end of file, resolves the issue.

(venv)  /tmp/ echo "---\nneedle: true\n" > /tmp/haystack
(venv)  /tmp/ echo "Present: $(ag -l needle /tmp/haystack)      Not_Present: $(ag -L needle /tmp/haystack)"
Present: /tmp/haystack      Not_Present:

Other checks:

Looking for chickens in the haystack:

(venv)  /tmp/ echo "---\nneedle: true" > /tmp/haystack
(venv)  /tmp/ echo "Present: $(ag -l chicken /tmp/haystack)      Not_Present: $(ag -L chicken /tmp/haystack)"
Present:       Not_Present: /tmp/haystack

Looking for hay in the haystack that has a needle:

(venv)  /tmp/ echo "---\nhay: true\nneedle: true" > /tmp/haystack
(venv)  /tmp/ echo "Present: $(ag -l hay /tmp/haystack)      Not_Present: $(ag -L hay /tmp/haystack)"
Present: /tmp/haystack      Not_Present:
(venv)  /tmp/ echo "Present: $(ag -l needle /tmp/haystack)      Not_Present: $(ag -L needle /tmp/haystack)"
Present: /tmp/haystack      Not_Present: /tmp/haystack
(venv)  /tmp/ ag --version
ag version 2.2.0

Features:
  +jit +lzma +zlib

Note this was on MacOS 12.4 installed ag via brew. I was not able to replicate this behavior on an Ubuntu 22.04 docker container.

@ggreer this issue has plagued me enough that I decided to check if the issue existed within mac ports, and when compiled from source... I can confirm that both port and brew installed experience the same issue, and confirmed with multiple peers they were having the same issue.

I can however say that it is not an issue when built from master branch. I think shipping a new release will resolve this issue without any modification of code.