From 535938a6b9973d746db248dc947f7faaf5023bd5 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 25 Sep 2023 17:22:01 +0200 Subject: [PATCH] bugfix: escape special chars in test names --- .../internal/metals/debug/DebugProvider.scala | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala index e72c9df1bed..ba3b36c9c5f 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala @@ -640,9 +640,11 @@ class DebugProvider( val testSuites = request.requestData.copy(suites = request.requestData.suites.map { suite => - if (testProvider.getFramework(buildTarget, suite) == JUnit4) - suite.copy(tests = suite.tests.map(_.replace("$", "\\$"))) - else suite + testProvider.getFramework(buildTarget, suite) match { + case JUnit4 | MUnit => + suite.copy(tests = suite.tests.map(escapeTestName)) + case _ => suite + } }) new b.DebugSessionParams( singletonList(buildTarget.getId), @@ -924,4 +926,12 @@ object DebugProvider { extends Exception( "Build misconfiguration. No semanticdb can be found for you file, please check the doctor." ) + + val specialChars: Set[Char] = ".+*?^()[]{}|&$".toSet + + def escapeTestName(testName: String): String = + testName.flatMap { + case c if specialChars(c) => s"\\$c" + case c => s"$c" + } }