beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 140 forks source link

ack is ambiguous about newlines at the end of the line #525

Closed pdl closed 5 years ago

pdl commented 9 years ago

Given:

package Foo;
use Moo;
has Goo => (
  is => 'rw',
);
has Too =>
  is => 'rw';

In the following case, line 6 is highlighted, line 3 is not. I didn't expect 3 to appear at all.

$ ack --perl "^has .*[^\(]$"
Foo.pm
3:has Goo => (
6:has Too =>

I can get what I want as follows (but I'd prefer not to have to add the \n)

$ ack --perl "^has .*[^\(\n]$"
Foo.pm
6:has Too =>

In this case, line 3 is highlighted:

$ ack --perl "^has .*\($"
Foo.pm
3:has Goo => (

In this case, it is not highlighted:

$ ack --perl "^has .*\(\n$"
Foo.pm
3:has Goo => (

Is this intentional?

I'm on ack 2.14 running under Perl 5.20.2 on 64-bit Fedora.

petdance commented 9 years ago

Is your question about what is matching, or what is getting highlighted?

pdl commented 9 years ago

My main concern is that the first case seems wrong - line 3 should not match ^has .*[^\(]$ at all in my view. The rest is just observation in an attempt to work out why ack is matching line 3.

hoelzro commented 9 years ago

I believe this is fixed as in Git HEAD:

ack-525

pdl commented 9 years ago

Ah, great - thanks!

petdance commented 9 years ago

@hoelzro says this is the same as #522

petdance commented 9 years ago

@pdl: Did you try the version on HEAD and verify it's been fixed to your satisfaction?

pdl commented 9 years ago

@petdance I can reproduce @hoelzro's result, it's fixed on the current state of dev, i.e. c92cb6c.

dboehmer commented 5 years ago

This doesn't seem to be fixed. I probably found the same issue with current master a1e0ba1b4c8df665e45d5a2013478f025dc2277d:

$ echo -e "xx \nxx\nfoo" > acktest
$ cat -n acktest 
     1  xx 
     2  xx
     3  foo
$ echo acktest | ack --files-from=- 'x$'   # correctly matches only line 2 but inconsistent with next command
acktest
2:xx
$ echo acktest | ack --files-from=- 'xx\s+$'    # shouldn't match line 2
acktest
1:xx 
2:xx
petdance commented 5 years ago

Reopening. Thanks for the update.

petdance commented 5 years ago

This is fixed in ack3. There will be no more releases of ack 2.