Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uri encoding #3795

Merged
merged 2 commits into from
Apr 11, 2022
Merged
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
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)
Comment on lines +136 to +137
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want to overcode JARs, right @Arthurm1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question - I don't think so.
I'm trying to move away from jar URIs in #3750 so that only Metals will deal with jar URIs and only in a few specific classes and the client won't encounter them at all so won't mess with the encoded value.

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