Fix scripting plugin commandline processing

This commit is contained in:
Ilya Chernikov
2018-05-22 17:58:59 +02:00
parent 705faa4792
commit 92d848b6e6
2 changed files with 8 additions and 5 deletions
@@ -111,11 +111,14 @@ class ScriptingCommandLineProcessor : CommandLineProcessor {
val currentEnv = configuration.getMap(ScriptingConfigurationKeys.LEGACY_SCRIPT_RESOLVER_ENVIRONMENT_OPTION).toMutableMap()
// parses key/value pairs in the form <key>=<value>, where
// <key> - is a single word (\w+ pattern)
// <value> - optionally quoted string with allowed escaped chars (only double-quote and backslash chars are supported)
// <value> - optionally quoted string with allowed escaped chars (only double-quote, comma and backslash chars are supported)
// TODO: implement generic unescaping
// TODO: consider switching to simple parser - current approach is too complicated already and doesn't handle quoted commas (unless they are escaped)
val envParseRe = """(\w+)=(?:"([^"\\]*(\\.[^"\\]*)*)"|([^\s]*))""".toRegex()
val unescapeRe = """\\(["\\])""".toRegex()
for (envParam in value.split(',')) {
val unescapeRe = """\\(["\\,])""".toRegex()
val splitRe = """(?:\\.|[^,\\]++)*""".toRegex()
val splitMatches = splitRe.findAll(value)
for (envParam in splitMatches.map { it.value }.filter { it.isNotBlank() }) {
val match = envParseRe.matchEntire(envParam)
if (match == null || match.groupValues.size < 4 || match.groupValues[1].isBlank()) {
throw CliOptionProcessingException("Unable to parse script-resolver-environment argument $envParam")