Skip to content

Commit

Permalink
fix: correctly decode project name from build target uri
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Apr 10, 2024
1 parent c928ba7 commit 8a8f376
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions frontend/src/main/scala/bloop/bsp/ProjectUris.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package bloop.bsp

import java.net.URI
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.nio.file.Path

import scala.util.Try
Expand All @@ -14,21 +12,16 @@ import bloop.engine.State
import bloop.io.AbsolutePath

object ProjectUris {
private val queryPrefix = "id="
def getProjectDagFromUri(projectUri: String, state: State): Either[String, Option[Project]] = {
if (projectUri.isEmpty) Left("URI cannot be empty.")
else {
val query = Try(new URI(projectUri).getRawQuery().split("&").map(_.split("="))).toEither
query match {
case Left(_) =>
Try(new URI(projectUri).getQuery()).toEither match {
case Right(query) if query.startsWith(queryPrefix) =>
val projectName = query.stripPrefix(queryPrefix)
Right(state.build.getProjectFor(projectName))
case _ =>
Left(s"URI '${projectUri}' has invalid format. Example: ${ProjectUris.Example}")
case Right(parsed) =>
parsed.headOption match {
case Some(Array("id", projectName)) =>
val name = URLDecoder.decode(projectName, StandardCharsets.UTF_8)
Right(state.build.getProjectFor(name))
case _ =>
Left(s"URI '${projectUri}' has invalid format. Example: ${ProjectUris.Example}")
}
}
}
}
Expand All @@ -43,7 +36,7 @@ object ProjectUris {
existingUri.getHost,
existingUri.getPort,
existingUri.getPath,
s"id=${id}",
s"$queryPrefix${id}",
existingUri.getFragment
)
}
Expand Down

0 comments on commit 8a8f376

Please sign in to comment.