@@ -16,6 +16,7 @@ import org.evomaster.core.output.service.RestTestCaseWriter
1616import org.evomaster.core.problem.enterprise.SampleType
1717import org.evomaster.core.problem.rest.data.*
1818import org.evomaster.core.problem.rest.param.BodyParam
19+ import org.evomaster.core.problem.rest.param.PathParam
1920import org.evomaster.core.search.EvaluatedIndividual
2021import org.evomaster.core.search.FitnessValue
2122import org.evomaster.core.search.gene.*
@@ -28,6 +29,7 @@ import org.evomaster.core.search.gene.collection.EnumGene
2829import org.evomaster.core.search.gene.numeric.IntegerGene
2930import org.evomaster.core.search.gene.string.StringGene
3031import org.evomaster.core.search.gene.utils.GeneUtils
32+ import org.evomaster.core.search.gene.wrapper.CustomMutationRateGene
3133import org.evomaster.core.search.gene.wrapper.OptionalGene
3234import org.evomaster.core.sql.schema.TableId
3335import org.junit.jupiter.api.Assertions.*
@@ -1679,4 +1681,30 @@ public void test() throws Exception {
16791681 assertFalse(lines.toString().contains(" .body()" ))
16801682
16811683 }
1684+
1685+ @Test
1686+ fun testNonAsciiInPathParamIsEncoded () {
1687+ // non-ASCII characters in path parameter values must be percent-encoded in generated test output.
1688+ val format = OutputFormat .KOTLIN_JUNIT_5
1689+
1690+ val pathParam = PathParam (" key" , CustomMutationRateGene (" key" , StringGene (" key" , " 聚" ), 1.0 ))
1691+ val action = RestCallAction (" 1" , HttpVerb .GET , RestPath (" /api/{key}" ), mutableListOf (pathParam))
1692+ val individual = RestIndividual (mutableListOf (action), SampleType .RANDOM )
1693+ TestUtils .doInitializeIndividualForTesting(individual)
1694+
1695+ val result = RestCallResult (action.getLocalId())
1696+ result.setTimedout(false )
1697+ result.setStatusCode(200 )
1698+ val ei = EvaluatedIndividual (FitnessValue (0.0 ), individual, listOf (result))
1699+
1700+ val writer = RestTestCaseWriter (getConfig(format), PartialOracles ())
1701+ val lines = writer.convertToCompilableTestCode(TestCase (test = ei, name = " test" ), " baseUrlOfSut" )
1702+ val output = lines.toString()
1703+
1704+ assertFalse(output.contains(" 聚" ),
1705+ " Non-ASCII character must not appear raw in generated test output, got:\n $output " )
1706+
1707+ assertTrue(output.contains(" %E8%81%9A" ),
1708+ " Non-ASCII character must be percent-encoded as %E8%81%9A in generated test output, got:\n $output " )
1709+ }
16821710}
0 commit comments