diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index a0fd4e7cf86..d7f08680199 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -423,7 +423,7 @@ class K2JVMCompiler : CLICompiler() { // - is a single word (\w+ pattern) // - optionally quoted string with allowed escaped chars (only double-quote and backslash chars are supported) // TODO: implement generic unescaping - val envParseRe = """(\w+)=(?:"((?:\\.|[^"])*)"|([^\s]*))""".toRegex() + val envParseRe = """(\w+)=(?:"([^"\\]*(\\.[^"\\]*)*)"|([^\s]*))""".toRegex() val unescapeRe = """\\(["\\])""".toRegex() if (arguments.scriptResolverEnvironment != null) { for (envParam in arguments.scriptResolverEnvironment) { diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt index 22c647a8bdc..f3cb192cd97 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.daemon.common.* import org.jetbrains.kotlin.integration.KotlinIntegrationTestBase import org.jetbrains.kotlin.scripts.captureOut import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.utils.keysToMap import org.junit.Assert import java.io.File import java.net.URLClassLoader @@ -97,10 +98,12 @@ class CompilerApiTest : KotlinIntegrationTestBase() { fun args(body: K2JVMCompilerArguments.() -> Unit): K2JVMCompilerArguments = K2JVMCompilerArguments().apply(body) + val longStr = (1..100).joinToString { """\" $it aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\""" } + val unescapeRe = """\\(["\\])""".toRegex() val messageCollector = TestMessageCollector() - Assert.assertEquals(hashMapOf("abc" to "def", "11" to "ab cd \\ \""), + Assert.assertEquals(hashMapOf("abc" to "def", "11" to "ab cd \\ \"", "long" to unescapeRe.replace(longStr, "\$1")), K2JVMCompiler.createScriptResolverEnvironment( - args { scriptResolverEnvironment = arrayOf("abc=def", """11="ab cd \\ \""""") }, + args { scriptResolverEnvironment = arrayOf("abc=def", """11="ab cd \\ \""""", "long=\"$longStr\"") }, messageCollector)) }