Skip to content

Commit 37e06c2

Browse files
Fix for printing
1 parent 6019121 commit 37e06c2

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

core/src/main/kotlin/org/evomaster/core/search/gene/jsonpatch/JsonPatchOperationGene.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,27 @@ abstract class JsonPatchOperationGene(
3737
targetFormat: OutputFormat?,
3838
extraCheck: Boolean
3939
): String {
40+
// path/from fields use getValueAsRawString() instead of getValueAsPrintableString() because
41+
// EnumGene<String>.getValueAsPrintableString() always wraps the value in quotes regardless of
42+
// mode or targetFormat. Using it would produce double-quoting in JSON ("path":""/x"") and
43+
// wrong quotes inside XML tags (<path>"/x"</path>). getValueAsRawString() returns the
44+
// bare string (e.g. /x), letting us control quoting per format ourselves.
4045
val fields = when (this) {
4146
is JsonPatchPathOnlyGene -> {
42-
val path = pathGene.getValueAsPrintableString(previousGenes, mode, targetFormat, extraCheck)
47+
val path = pathGene.getValueAsRawString()
4348
if (mode == GeneUtils.EscapeMode.XML) "<path>$path</path>"
4449
else "\"path\":\"$path\""
4550
}
4651
is JsonPatchFromPathGene -> {
47-
val from = fromGene.getValueAsPrintableString(previousGenes, mode, targetFormat, extraCheck)
48-
val path = pathGene.getValueAsPrintableString(previousGenes, mode, targetFormat, extraCheck)
52+
val from = fromGene.getValueAsRawString()
53+
val path = pathGene.getValueAsRawString()
4954
if (mode == GeneUtils.EscapeMode.XML) "<from>$from</from><path>$path</path>"
5055
else "\"from\":\"$from\",\"path\":\"$path\""
5156
}
5257
is JsonPatchPathValueGene -> {
5358
val pair = pathValueChoice.activeGene()
54-
val path = pair.first.getValueAsPrintableString(previousGenes, mode, targetFormat, extraCheck)
55-
// value is unquoted in JSON since it can be any type (string, number, boolean, etc.)
59+
val path = pair.first.getValueAsRawString()
60+
// value delegates to the typed gene so it handles its own quoting (string vs number vs boolean)
5661
val value = pair.second.getValueAsPrintableString(previousGenes, mode, targetFormat, extraCheck)
5762
if (mode == GeneUtils.EscapeMode.XML) "<path>$path</path><value>$value</value>"
5863
else "\"path\":\"$path\",\"value\":$value"

0 commit comments

Comments
 (0)