@@ -182,8 +182,8 @@ internal object DebugProbesImpl {
182
182
val coroutinesInfoAsJson = ArrayList <String >(size)
183
183
for (info in coroutinesInfo) {
184
184
val context = info.context
185
- val name = context[CoroutineName .Key ]?.name?.toStringWithQuotes ()
186
- val dispatcher = context[CoroutineDispatcher .Key ]?.toStringWithQuotes ()
185
+ val name = context[CoroutineName .Key ]?.name?.toStringRepr ()
186
+ val dispatcher = context[CoroutineDispatcher .Key ]?.toStringRepr ()
187
187
coroutinesInfoAsJson.add(
188
188
"""
189
189
{
@@ -219,7 +219,7 @@ internal object DebugProbesImpl {
219
219
{
220
220
"declaringClass": "${element.className} ",
221
221
"methodName": "${element.methodName} ",
222
- "fileName": ${element.fileName?.toStringWithQuotes ()} ,
222
+ "fileName": ${element.fileName?.toStringRepr ()} ,
223
223
"lineNumber": ${element.lineNumber}
224
224
}
225
225
""" .trimIndent()
@@ -229,7 +229,7 @@ internal object DebugProbesImpl {
229
229
return " [${stackTraceElementsInfoAsJson.joinToString()} ]"
230
230
}
231
231
232
- private fun Any.toStringWithQuotes () = " \" $this \" "
232
+ private fun Any.toStringRepr () = toString().repr()
233
233
234
234
/*
235
235
* Internal (JVM-public) method used by IDEA debugger as of 1.4-M3.
@@ -590,3 +590,19 @@ internal object DebugProbesImpl {
590
590
591
591
private val StackTraceElement .isInternalMethod: Boolean get() = className.startsWith(" kotlinx.coroutines" )
592
592
}
593
+
594
+ private fun String.repr (): String = buildString {
595
+ append(' "' )
596
+ for (c in this @repr) {
597
+ when (c) {
598
+ ' "' -> append(" \\\" " )
599
+ ' \\ ' -> append(" \\\\ " )
600
+ ' \b ' -> append(" \\ b" )
601
+ ' \n ' -> append(" \\ n" )
602
+ ' \r ' -> append(" \\ r" )
603
+ ' \t ' -> append(" \\ t" )
604
+ else -> append(c)
605
+ }
606
+ }
607
+ append(' "' )
608
+ }
0 commit comments