Skip to content

Commit

Permalink
Changed implementation of option checking to use a fixed whitelist of…
Browse files Browse the repository at this point in the history
… supported options rather than pattern match.

This makes it much more robust and will not pass parameters that are not supported or handled by the plugin in a different way.
  • Loading branch information
Tim Sheppard committed Jan 31, 2013
1 parent 046c5b1 commit 82647b6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions plugin/src/main/scala/templemore/sbt/cucumber/Integration.scala
Expand Up @@ -33,6 +33,25 @@ trait Integration {
} }
} }


/*
* The options that are supported by the plugin.
* This excludes options that are set in other places such as formatting
* and dotcucumber etc.
*
* This is essentially a list of the parameter-less options supported by the
* `cucumber-jvm` `cucumber.runtime.RuntimeOptions` class
*
* The `--no-xxx` version of the options are not included as they are not enabled
* by default and are therefore not really necessary.
*/
private val supportedOptions = Seq("-d",
"--dry-run",
"-s",
"--strict",
"-m",
"--monochrome")


private def runCucumber(args: Seq[String], private def runCucumber(args: Seq[String],
jvmSettings: JvmSettings, jvmSettings: JvmSettings,
options: Options, options: Options,
Expand All @@ -42,9 +61,7 @@ trait Integration {
def optsFromArgs = args.filter(isAnOption).toList def optsFromArgs = args.filter(isAnOption).toList
def namesFromArgs = args.filter(isAName).toList def namesFromArgs = args.filter(isAName).toList


val optionPattern = """-[a-z]""".r.pattern def isAnOption(arg: String) = supportedOptions.contains(arg)

def isAnOption(arg: String) = (arg.startsWith("--") || optionPattern.matcher(arg).matches())
def isATag(arg: String) = arg.startsWith("@") || arg.startsWith("~@") def isATag(arg: String) = arg.startsWith("@") || arg.startsWith("~@")
def isAName(arg:String) = !isATag(arg) && !isAnOption(arg) def isAName(arg:String) = !isATag(arg) && !isAnOption(arg)


Expand Down

0 comments on commit 82647b6

Please sign in to comment.