cucumber/cucumber-jvm — pull request #215 by undees (2012-02-19 21:14:11+00:00)
Title: Escape regex characters in steps; fixes #204

The current rules for generating step definition templates for
undefined steps do not escape regular expression characters. For
instance, the following step:

Given I have $5

...generates the following template:

@Given("^I have $(\\d+) in my account$")

Java sees the dollar sign as a regex end-of-string marker, and the
scenario won't run correctly. This commit escapes dollar signs,
parentheses, and square brackets. The step shown above will now be
correctly translated into a template as:

@Given("^I have \\$(\\d+) in my account$")

This commit changes the general SnippetGenerator.java file; it assumes
the set of special regular expression characters will be the same
across JVM languages. This condition appears to hold for the currently
supported languages. If this changes in the future, it should be
possible to wrap the list of escaped regex chars in a function that
can be overridden.