Fix scripting plugin commandline processing
This commit is contained in:
+6
-3
@@ -111,11 +111,14 @@ class ScriptingCommandLineProcessor : CommandLineProcessor {
|
|||||||
val currentEnv = configuration.getMap(ScriptingConfigurationKeys.LEGACY_SCRIPT_RESOLVER_ENVIRONMENT_OPTION).toMutableMap()
|
val currentEnv = configuration.getMap(ScriptingConfigurationKeys.LEGACY_SCRIPT_RESOLVER_ENVIRONMENT_OPTION).toMutableMap()
|
||||||
// parses key/value pairs in the form <key>=<value>, where
|
// parses key/value pairs in the form <key>=<value>, where
|
||||||
// <key> - is a single word (\w+ pattern)
|
// <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: 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 envParseRe = """(\w+)=(?:"([^"\\]*(\\.[^"\\]*)*)"|([^\s]*))""".toRegex()
|
||||||
val unescapeRe = """\\(["\\])""".toRegex()
|
val unescapeRe = """\\(["\\,])""".toRegex()
|
||||||
for (envParam in value.split(',')) {
|
val splitRe = """(?:\\.|[^,\\]++)*""".toRegex()
|
||||||
|
val splitMatches = splitRe.findAll(value)
|
||||||
|
for (envParam in splitMatches.map { it.value }.filter { it.isNotBlank() }) {
|
||||||
val match = envParseRe.matchEntire(envParam)
|
val match = envParseRe.matchEntire(envParam)
|
||||||
if (match == null || match.groupValues.size < 4 || match.groupValues[1].isBlank()) {
|
if (match == null || match.groupValues.size < 4 || match.groupValues[1].isBlank()) {
|
||||||
throw CliOptionProcessingException("Unable to parse script-resolver-environment argument $envParam")
|
throw CliOptionProcessingException("Unable to parse script-resolver-environment argument $envParam")
|
||||||
|
|||||||
+2
-2
@@ -61,8 +61,8 @@ class ScriptingCompilerPluginTest : TestCaseWithTmpdir() {
|
|||||||
|
|
||||||
fun testScriptResolverEnvironmentArgsParsing() {
|
fun testScriptResolverEnvironmentArgsParsing() {
|
||||||
|
|
||||||
val longStr = (1..100).joinToString { """\" $it aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\""" }
|
val longStr = (1..100).joinToString("\\,") { """\" $it aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\""" }
|
||||||
val unescapeRe = """\\(["\\])""".toRegex()
|
val unescapeRe = """\\(["\\,])""".toRegex()
|
||||||
val cmdlineProcessor = ScriptingCommandLineProcessor()
|
val cmdlineProcessor = ScriptingCommandLineProcessor()
|
||||||
val configuration = CompilerConfiguration()
|
val configuration = CompilerConfiguration()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user