Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CI

on:
workflow_dispatch:
push:
branches:
- "**"
Expand Down Expand Up @@ -479,4 +480,4 @@ jobs:
NODE_OPTIONS: "--max_old_space_size=9000"
with:
check_name: JUnit ${{ matrix.profile }}
report_paths: '**/target/*-reports/TEST-*.xml'
report_paths: '**/target/*-reports/TEST-*.xml'
20 changes: 18 additions & 2 deletions core/src/main/kotlin/org/evomaster/core/output/MongoWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ object MongoWriter {
.forEach { g ->
when (g) {
is ObjectGene -> {
val printableValue =
StringEscapeUtils.escapeJava(g.getValueAsPrintableString(mode = GeneUtils.EscapeMode.EJSON))
val ejson = g.getValueAsPrintableString(mode = GeneUtils.EscapeMode.EJSON)
val printableValue = if (format.isJava()) escapeEjsonForJavaLiteral(ejson)
else StringEscapeUtils.escapeJava(ejson)
val adaptedPrintableValue = if (format.isKotlin())
printableValue.replace(
"$",
Expand Down Expand Up @@ -95,4 +96,19 @@ object MongoWriter {

}

/**
* Escapes EJSON for a Java string literal without leaving a raw backslash-u
* sequence. Java translates Unicode escapes before parsing string literals,
* so an EJSON value containing a literal backslash followed by 'u' can make
* otherwise valid generated tests fail to compile.
*/
internal fun escapeEjsonForJavaLiteral(value: String): String {
return StringEscapeUtils.escapeJava(value).replace(ESCAPED_BACKSLASH_U) { match ->
val slashCount = match.value.length - 1
"\\134".repeat(slashCount / 2) + "u"
}
}

private val ESCAPED_BACKSLASH_U = Regex("""(\\\\)+u""")

}
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,15 @@ class RestPath(path: String) {
val data = dynamicResolutionOnlyPathData(params, mapOf())
assert(data.size == 1)
assert(!data[0].second)
return data[0].first
return data[0].first.map { c ->
// The URI calls in dynamicResolutionOnlyPathData do not encode non-ASCII characters in path segments.
if (c.code > 127) {
// non-ASCII
encode(c.toString())
} else {
c.toString()
}
}.joinToString( "")
}


Expand Down Expand Up @@ -413,7 +421,7 @@ class RestPath(path: String) {
why not using URI also for Query part???
it seems unclear how to properly build it as a single string...
*/
val entry = URI(null, null, path.toString(), null, null).toASCIIString()
val entry = URI(null, null, path.toString(), null, null).rawPath
data.add(Pair(entry, false))
path.setLength(0) // clear it
data.add(Pair(variable, true))
Expand Down Expand Up @@ -446,7 +454,7 @@ class RestPath(path: String) {
}

if(path.isNotEmpty()){
val entry = URI(null, null, path.toString(), null, null).toASCIIString()
val entry = URI(null, null, path.toString(), null, null).rawPath
data.add(Pair(entry, false))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class SearchProcessMonitor: SearchListener {

@PostConstruct
fun postConstruct(){
initMonitorProcessOutputs()
if(config.enableProcessMonitor){
initMonitorProcessOutputs()
time.addListener(this)
if (config.processFormat == EMConfig.ProcessDataFormat.TEST_IND || config.processFormat == EMConfig.ProcessDataFormat.TARGET_TEST_IND){
val dto = try {
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/kotlin/org/evomaster/core/output/MongoWriterTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.evomaster.core.output

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Test

class MongoWriterTest {

@Test
fun `should escape literal backslash u in EJSON without changing its runtime value`() {
val ejson = """{"field":"El24e\\uJTQGh"}"""

val escaped = MongoWriter.escapeEjsonForJavaLiteral(ejson)

assertEquals("""{\"field\":\"El24e\134\134uJTQGh\"}""", escaped)
assertFalse(Regex("""(\\\\)+u""").containsMatchIn(escaped))
}
}