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

string match -n does not work with -r -v #3098

Closed
1 task done
msteed opened this issue May 31, 2016 · 5 comments
Closed
1 task done

string match -n does not work with -r -v #3098

msteed opened this issue May 31, 2016 · 5 comments
Assignees
Labels
Milestone

Comments

@msteed
Copy link
Contributor

@msteed msteed commented May 31, 2016

string match with -r (regex) and -v (invert) does not respect -n (index).

Reproduction Steps:

$ string match -r -v -n a b

Expected behavior:

fish should report the start position and length when -n is given, as it does without -v.

Observed behavior:

$ string match -r -v -n a b
b

Additional information:

I think this was introduced with the addition of the (-v | --invert) options to string. The problem appears to be here: https://github.com/fish-shell/fish-shell/blob/master/src/builtin_string.cpp#L378-L381 where the argument is reported without checking for opts.index as is done below.


Fish version: fish, version 2.3.0

Operating system: Arch linux, fish installed from the official package


For 2.3.1 release:

  • Update release notes
@msteed msteed changed the title string match -r -v does not work with -n string match -n does not work with -r -v May 31, 2016
@faho
Copy link
Member

@faho faho commented May 31, 2016

fish should report the start position and length when -n is given, as it does without -v.

"--invert" is maybe a bit inaccurate here. What it does is ignore all arguments/lines without a match (taken straight from grep's -v or --invert option). I can't see how you can say where a non-match starts - unless it's always "1", and the length is always the length of the entire string.

@msteed
Copy link
Contributor Author

@msteed msteed commented May 31, 2016

Right, and this is the current behavior without -r:

$ string match -n -v a bbb
1 3

@faho faho closed this in 8d6735c May 31, 2016
@faho faho added the bug label May 31, 2016
@faho faho added this to the next-2.x milestone May 31, 2016
@faho
Copy link
Member

@faho faho commented May 31, 2016

Yeah, maybe this is useful for someone.

I've now pushed a commit which I believe fixes it.

Thanks!

@ridiculousfish ridiculousfish added this to the 2.3.1 milestone Jun 2, 2016
@ridiculousfish ridiculousfish removed this from the next-2.x milestone Jun 2, 2016
@ridiculousfish
Copy link
Member

@ridiculousfish ridiculousfish commented Jun 2, 2016

If we do a 2.3.1, we ought to take this too.

@floam
Copy link
Member

@floam floam commented Jun 4, 2016

I'm not sure I ever tried -n and -v together while I was adding -v -- never occurred to me that it should do anything. That it did anything at all without -r was a (lucky?) oversight. Are the exit codes as expected?

krader1961 added a commit that referenced this issue Jun 21, 2016
@floam floam self-assigned this Jul 3, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants