-
-
Notifications
You must be signed in to change notification settings - Fork 690
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
RegularExpression constructor is not filtering non-capturing groups #211
Comments
Dupe of #131 |
My bad - this is not a dupe of #131 so I'm reopening it. We now have 3 proposed fixes for this issue:
I'm going to improve #220 with the technique from #216 and merge that. I realise this implementation doesn't handle nested groups, as explained in comments in #216, but we'll handle that in a different issue. |
Fixed by #220 |
I'm about to make a change that would disallow optional capture groups such as So the example above would have to be one of the following:
or:
Can you see any issues with this @Jordyderuijter? |
This would be a breaking change, but I think it can easily be solved by using a format like this: In this case you can still use a capturing group without making it optional. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
From @Jordyderuijter on May 23, 2017 11:4
Hi there,
It seems like there is a bug in the RegularExpression class in the cucumber-expressions dependency.
The regex in this constructor looks for capturing groups when processing steps using the regex:
/\(([^(]+)\)/g
This regex finds everything between braces (a.k.a. capturing groups), but it also accepts non-capturing groups. This causes the constructor to generate parameter types for the non capturing groups (instead of the capturing groups only).
These parameter types are used in the buildArguments function, but are only applied to capturing groups, since the given step regex filters out the non-capturing groups correctly.
I would expect the RegularExpression constructor to filter out these capturing groups correctly.
The step and step definitions I used to reproduce the issue are:
Step:
I can cancel the 1st slide upload
Step definition:
(\S+) ?(can|cannot)? (?:delete|cancel) the (\d+)(?:st|nd|rd|th) (attachment|slide) ?(?:upload)?
In this case 7 parameter types are being generated by the constructor, while it should only create 4, since 3 of them are non-capturing groups. As a result, the parameter type that belongs to (\d+) is being applied to (attachment|slide), treating it as an integer. This results into a NaN value that is being passed to my step definition.
Version info:
Copied from original issue: cucumber/cucumber-js#837
The text was updated successfully, but these errors were encountered: