Skip to content

Commit d88068c

Browse files
goncalossilvaqurbonzoda
authored andcommitted
Fix source generator not escaping quotes in parameters
1 parent 3cf7241 commit d88068c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

integration/src/test/resources/templates/kotlin-multiplatform/src/commonMain/kotlin/CommonBenchmark.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import kotlin.math.*
88
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS)
99
@BenchmarkMode(Mode.Throughput)
1010
open class CommonBenchmark {
11+
@Param("""a "string" with quotes""")
12+
var value = ""
13+
1114
@Benchmark
1215
open fun mathBenchmark(): Double {
1316
return log(sqrt(3.0) * cos(3.0), 2.0)

plugin/main/src/kotlinx/benchmark/gradle/SuiteSourceGenerator.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
208208
val annotation = it.annotations.findAnnotation(FqName(paramAnnotationFQN))!!
209209
val constant = annotation.argumentValue("value")
210210
?: error("@Param annotation should have at least one default value")
211-
val values = constant.value as? List<String>
211+
val values = constant.value as? List<StringValue>
212212
?: error("@Param annotation should have at least one default value")
213213
values
214214
})
215215

216216
val defaultParametersString = defaultParameters.entries
217-
.joinToString(prefix = "mapOf(", postfix = ")") {
218-
"\"${it.key}\" to " + it.value.joinToString(prefix = "listOf(", postfix = ")")
219-
217+
.joinToString(prefix = "mapOf(", postfix = ")") { (key, value) ->
218+
"\"${key}\" to ${value.joinToString(prefix = "listOf(", postfix = ")") { "\"${it.value.replace("\"", "\\\"")}\"" }}"
219+
220220
}
221221

222222
val timeUnitClass = ClassName.bestGuess(timeUnitFQN)

0 commit comments

Comments
 (0)