Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix: Define Steps produces incorrect cucumber expression for step definition (#28) #29
Fix: Define Steps produces incorrect cucumber expression for step definition (#28) #29
Changes from 1 commit
91ea625
1194d2a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code supposed to produce valid cucumber expressions and cucumber expressions are different from regex from the escaping perspective.
The cucumber expression escaping is defined at https://github.com/cucumber/cucumber-expressions?tab=readme-ov-file#escaping and it only allows escaping for:
{
,(
,/
and\
.Therefore we cannot use
Regex.Escape(text)
as it uses the regex escaping that is far more greedy than necessary. I think we would just need to fix the original code to match the specs: the.Replace("(", @"\")
is clearly buggy, as it should be.Replace("(", @"\(")
and the escaping for/
is missing (so one more replace).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reference.
Two follow-up questions then:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: question 2 above, in my experimentation, I see now that / is meant to convey alternatives and so the use of a / in an example text fed into our snippet provider should treat that as a literal and should be escaped.
Since C# doesn't recognize that as a proper escape sequence, should the snippet provider generate the string as a strictly literal string (with the prepended @ sign)? Such as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I see that number 1 and 2 are related. When I leave line 32 as originally written, the example I'm using in number 2 is generated as
which is handled gracefully by the C# compiler without the prepended @ sign.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clrudolphi I agree. Let's keep it this way. Switching over to @ strings (verbatim string) just complicates the things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proper escaped version of
I call the integer.ToString() method
would beI call the integer.ToString\() method
(the.
should not be escaped). See above.Maybe we can find a better example, so that it shows all escaped characters, like
When I use (parenthesis), {curly braces} and/or \ backslash
, where the escaped should beWhen I use \(parenthesis), \{curly braces} and\/or \\ backslash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the Regex snippet provider behaving correctly as-is? It does escape the period, which if I'm not mistaken is required because it could otherwise be mistaken for a Regex pattern character. Correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct.