Fix environment arg parsing regex - avoid SO on the long strings
This commit is contained in:
@@ -423,7 +423,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
|||||||
// <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 and backslash chars are supported)
|
||||||
// TODO: implement generic unescaping
|
// TODO: implement generic unescaping
|
||||||
val envParseRe = """(\w+)=(?:"((?:\\.|[^"])*)"|([^\s]*))""".toRegex()
|
val envParseRe = """(\w+)=(?:"([^"\\]*(\\.[^"\\]*)*)"|([^\s]*))""".toRegex()
|
||||||
val unescapeRe = """\\(["\\])""".toRegex()
|
val unescapeRe = """\\(["\\])""".toRegex()
|
||||||
if (arguments.scriptResolverEnvironment != null) {
|
if (arguments.scriptResolverEnvironment != null) {
|
||||||
for (envParam in arguments.scriptResolverEnvironment) {
|
for (envParam in arguments.scriptResolverEnvironment) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.daemon.common.*
|
|||||||
import org.jetbrains.kotlin.integration.KotlinIntegrationTestBase
|
import org.jetbrains.kotlin.integration.KotlinIntegrationTestBase
|
||||||
import org.jetbrains.kotlin.scripts.captureOut
|
import org.jetbrains.kotlin.scripts.captureOut
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
import org.jetbrains.kotlin.utils.keysToMap
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
@@ -97,10 +98,12 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
|||||||
fun args(body: K2JVMCompilerArguments.() -> Unit): K2JVMCompilerArguments =
|
fun args(body: K2JVMCompilerArguments.() -> Unit): K2JVMCompilerArguments =
|
||||||
K2JVMCompilerArguments().apply(body)
|
K2JVMCompilerArguments().apply(body)
|
||||||
|
|
||||||
|
val longStr = (1..100).joinToString { """\" $it aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\""" }
|
||||||
|
val unescapeRe = """\\(["\\])""".toRegex()
|
||||||
val messageCollector = TestMessageCollector()
|
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(
|
K2JVMCompiler.createScriptResolverEnvironment(
|
||||||
args { scriptResolverEnvironment = arrayOf("abc=def", """11="ab cd \\ \""""") },
|
args { scriptResolverEnvironment = arrayOf("abc=def", """11="ab cd \\ \""""", "long=\"$longStr\"") },
|
||||||
messageCollector))
|
messageCollector))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user