diff --git a/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala b/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala index 091fcad4497..65035ad7dd6 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala @@ -5,7 +5,7 @@ object URIEncoderDecoder { // Some encoding schemes encode `:` (although not the first one as that indicates scheme). // Currently Metals doesn't encode `:` but does decode it private val toEscape: Map[Char, String] = - Set('"', '<', '>', '&', '\'', '[', ']', '{', '}', ' ', '+', '!') + Set('"', '<', '>', '&', '\'', '[', ']', '{', '}', ' ', '+') .map(char => char -> ("%" + char.toHexString)) .toMap diff --git a/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala b/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala index 63c29f3b390..155add980c9 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala @@ -174,7 +174,10 @@ trait MtagsEnrichments extends ScalametaCommonEnrichments { URLDecoder.decode(_, "UTF-8").toAbsolutePath(followSymlink) ) else if (value.toUpperCase.startsWith("JAR")) { - try URI.create(value).toAbsolutePath(followSymlink) + try + URI + .create(URIEncoderDecoder.encode(value)) + .toAbsolutePath(followSymlink) catch { case _: NoSuchFileException | _: FileSystemNotFoundException => withTryDecode(value.stripPrefix("jar:"))( diff --git a/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala b/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala index 2fa7519d7a4..4e73f11b3b9 100644 --- a/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala +++ b/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala @@ -1,5 +1,6 @@ package tests +import scala.meta.internal.metals.MetalsEnrichments.XtensionString import scala.meta.internal.mtags.URIEncoderDecoder class UriEncoderDecoderSuite extends BaseSuite { @@ -41,4 +42,11 @@ class UriEncoderDecoderSuite extends BaseSuite { ) } + test("absolute-path-space") { + // Should be NoSuchFileException instead of URI creation one + intercept[java.nio.file.NoSuchFileException] { + "jar:file:///C:/Program Files/Java/jdk-21.0.3+9/lib/src.zip!/java.base/java/lang/String.java".toAbsolutePath + } + } + }