Skip to content

Commit

Permalink
fix: uri encoding (#3795)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpodsiad authored Apr 11, 2022
1 parent fc2e37c commit ae28000
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.nio.file.Path
import scala.collection.mutable.ListBuffer

import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.mtags.URIEncoderDecoder

import ch.epfl.scala.bsp4j.BuildTarget
import ch.epfl.scala.bsp4j.BuildTargetIdentifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import scala.meta.internal.metals.clients.language.MetalsQuickPickItem
import scala.meta.internal.metals.clients.language.MetalsQuickPickParams
import scala.meta.internal.metap.Main
import scala.meta.internal.mtags.SemanticdbClasspath
import scala.meta.internal.mtags.URIEncoderDecoder
import scala.meta.internal.parsing.ClassFinder
import scala.meta.internal.parsing.ClassWithPos
import scala.meta.io.AbsolutePath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package scala.meta.internal.metals
package scala.meta.internal.mtags

object URIEncoderDecoder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@ trait MtagsEnrichments extends CommonMtagsEnrichments {
URLDecoder.decode(value, "UTF-8").toAbsolutePath(followSymlink)
else if (value.toUpperCase.startsWith("JAR:FILE%3A"))
URLDecoder.decode(value, "UTF-8").toAbsolutePath(followSymlink)
else
URI.create(value.stripPrefix("metals:")).toAbsolutePath(followSymlink)
else if (value.toUpperCase.startsWith("JAR"))
URI.create(value).toAbsolutePath(followSymlink)
else {
val stripped = value.stripPrefix("metals:")
val percentEncoded = URIEncoderDecoder.encode(stripped)
URI.create(percentEncoded).toAbsolutePath(followSymlink)
}
}
def lastIndexBetween(
char: Char,
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/src/test/scala/tests/MetalsEnrichmentsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ class MetalsEnrichmentsSuite extends BaseSuite {
assertEquals(relativeCreated, expected)
}

test("uri-to-absolute-path") {
test("dont-decode-uri") {
val uri =
"file:///Users/happyMetalsUser/hello%20space%20world/src/main/scala/Main.scala"
val path = uri.toAbsolutePath
assert(path.toString().contains("hello space world"))
}

test("encode-uri-space") {
val uri =
"file:///Users/happyMetalsUser/hello space+world/src/main/scala/Main.scala"
val path = uri.toAbsolutePath
assert(path.toString().contains("hello space+world"))
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tests

import scala.meta.internal.metals.URIEncoderDecoder
import scala.meta.internal.mtags.URIEncoderDecoder

class UriEncoderDecoderSuite extends BaseSuite {

Expand Down

0 comments on commit ae28000

Please sign in to comment.