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

Catch when regexp matches empty string #382

Open
epa opened this issue Oct 23, 2024 · 3 comments
Open

Catch when regexp matches empty string #382

epa opened this issue Oct 23, 2024 · 3 comments
Assignees
Labels

Comments

@epa
Copy link

epa commented Oct 23, 2024

When the regexp passed to ack matches the empty string, this is much more likely to be a mistake than intentional. Rather than print the complete contents of every file, ack should stop with a diagnostic.

% ack ''
The regular expression matches the empty string, so would find all lines.

(If there's really a use for it, then maybe an --allow-empty flag similar to what you have in git to allow empty commits. And of course, having detected that the regexp matches the empty string, ack could go a bit faster by not bothering to match it.)

(For example I mistyped (joe|jim)? when I had meant to search for (joe|jim)@. Just to give a random example.)

@petdance
Copy link
Collaborator

This makes a lot of sense. Let me ponder if we need an --allow-empty. I'm trying to imagine a case where you would want it. Maybe someone searches for .*whatever just so they get every line, even those that don't match whatever? Like they're emulating the --passthru option.

@petdance petdance self-assigned this Oct 23, 2024
@epa
Copy link
Author

epa commented Oct 23, 2024

Yes, I don't think --allow-empty would be needed in practice but I mentioned it because you sometimes get people who furiously defend the current behaviour, whatever it may be.

@petdance
Copy link
Collaborator

I don't optimize for complaint avoidance. If people complain and there's a legit need we can add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants