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

ag matches blank lines with pattern '\s*' #1396

Open
d-c-d opened this issue Jul 17, 2020 · 1 comment
Open

ag matches blank lines with pattern '\s*' #1396

d-c-d opened this issue Jul 17, 2020 · 1 comment

Comments

@d-c-d
Copy link

d-c-d commented Jul 17, 2020

at matched the blank line even though the literal q was part of the pattern
This happened on cygwin ( not significant as it happens on Linux also appended below)
cloned and compiled from source
Minor patch to get it to compile on cygwin ( see below )

This was reduced from a more realistic pattern, but ag should not match and print the blank line, just the line with the q
Tried with a '.*' prefix, ' *' ( zero or more spaces ) and no prefix - those all work
I had started by anchoring to the beginning of the line - ( e.g. '^\s+q' but it's broken in that case also )

$  ( echo "" ; echo q  ) > q && ./ag  '\s*q' q
1:
2:q



$ ./ag --version
ag version 2.2.0

Features:
  +jit +lzma +zlib


expected just one line to print

$ perl -nle 'print if /^\s*q/' q
q

$ grep -P '^\s*q' q
q


$  ( echo "" ; echo q  ) > q && ack  '\s*q' q
q

$ ag --version
ag version 2.1.0

Features:
  +jit +lzma +zlib

$ ack --version
ack 2.22
Running under Perl 5.30.3 at /usr/bin/perl.exe

Copyright 2005-2017 Andy Lester.

This program is free software.  You may modify or distribute it
under the terms of the Artistic License v2.0.

diff --git a/src/main.c b/src/main.c
index e116f70..763cb51 100644
--- a/src/main.c
+++ b/src/main.c
@@ -154,7 +154,7 @@ int main(int argc, char **argv) {
             }
 #if defined(HAVE_PTHREAD_SETAFFINITY_NP) && (defined(USE_CPU_SET) || defined(HAVE_SYS_CPUSET_H))
             if (opts.use_thread_affinity) {
-#if defined(__linux__) || defined(__midipix__)
+#if defined(__CYGWIN__) || defined(__linux__) || defined(__midipix__)
                 cpu_set_t cpu_set;
 #elif __FreeBSD__
                 cpuset_t cpu_set;




dcd@jetson:~$ ag --version
ag version 2.1.0

Features:
  +jit +lzma +zlib
dcd@jetson:~$ ( echo "" ; echo q  ) > q && ag -i '\s*q' q
1:
2:q
dcd@jetson:~$ uname -a
Linux jetson 4.9.140-tegra #1 SMP PREEMPT Wed Mar 13 00:32:22 PDT 2019 aarch64 aarch64 aarch64 GNU/Linux

@kraxli
Copy link

kraxli commented Jan 9, 2021

I face similar problems. A solution to your issue may be to apply a look-ahead before your pattern:

(?=\S+)

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