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

`string match -e "" -- foo` does not return any output #4971

Closed
mqudsi opened this Issue May 10, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@mqudsi
Copy link
Contributor

mqudsi commented May 10, 2018

I'm not certain if this is intentional, but a brief perusal of the relevant docs does not seem to indicate it's an explicit special case. When programmatically generating text to filter by literally (e.g. via commandline -ct), it is possible to evaluate string match -e "" -- ..., in which case the assumption would be that all text would match. In practice, this is an effective "match none" instead of "match all" filter.

My gut instinct is that this behavior isn't correct, but seeking feedback or comments before I patch this.

@faho

This comment has been minimized.

Copy link
Member

faho commented May 11, 2018

This uses glob-mode. In that, the expression needs to match the entire string. So "" can never match anything - it'd have to be "*".

Which makes "-e" entirely (HA!) useless, so we should probably change it.

@faho faho added the enhancement label May 11, 2018

@faho faho added this to the fish-future milestone May 11, 2018

@faho

This comment has been minimized.

Copy link
Member

faho commented May 13, 2018

In that, the expression needs to match the entire string

Not actually true - string match -e "f" -- foo does print "foo"!

Which takes this into bug territory!

@faho faho added bug and removed enhancement labels May 13, 2018

@mqudsi

This comment has been minimized.

Copy link
Contributor

mqudsi commented May 13, 2018

Yeah, that was my initial understanding of the -e flag. I was still trying to understand what you meant when you clarified! Thanks.

@faho

This comment has been minimized.

Copy link
Member

faho commented Sep 16, 2018

From the code:

        if (opts.entire && !wcpattern.empty()) {
            if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING);
            if (wcpattern.back() != ANY_STRING) wcpattern.push_back(ANY_STRING);
        }

That pattern was already present in 5b6814d. I have no idea why that "!wcpattern.empty()" is there, and the code or commit message do not contain any explanation. I'll just try removing it.

@faho faho closed this in 3ba74b3 Sep 16, 2018

@faho faho modified the milestones: fish-future, fish-3.0 Sep 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment