Skip to content

Error with implied --filter #273

Open
@rdpate

Description

@rdpate

Given -f, when stdin is a pipe (or --filter makes it look like one), ack emits this error, even though it doesn't need to read stdin. I may have missed something trying to narrow this down. Test case:

$ ls  # starting in an empty directory
$ touch some-file
$ ack -f
some-file
$ ack -f <some-file
some-file
$ ack -f </dev/null
some-file
$ cat /dev/null | ack -f
ack: No regular expression found.
$ ack -f --filter
ack: No regular expression found.
$

(After diving through the code, it seems the test case can eliminate all except the first and last invocations of ack, but I'll leave it here in case it's useful to write a test.)

Expected behavior is what is shown, except for the last two error messages. I have ack 2.12 installed locally using the normal Ubuntu 14.04 package, but I get the same results with http://beyondgrep.com/ack-2.14-single-file.

The change below seems to do the right thing (edit: it doesn't), but I failed writing a test case (to be included in the repo tests), more because I don't know perl than anything else. This change does pass all the included tests and fixes the above error.

--- a/ack
+++ b/ack
@@ -1036,7 +1036,7 @@ sub main {
     }

     my $resources;
-    if ( $App::Ack::is_filter_mode && !$opt->{files_from} ) { # probably -x
+    if ( $App::Ack::is_filter_mode && !$opt->{files_from} && !$opt_f ) { # probably -x
         $resources    = App::Ack::Resources->from_stdin( $opt );
         $opt_regex = shift @ARGV if not defined $opt_regex;
         $opt_regex = $opt->{regex} = build_regex( $opt_regex, $opt );

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions