Skip to content

Commit

Permalink
fix: try single decode for Windows when NoSuchFileException
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Jun 28, 2024
1 parent 9217c99 commit cd4a18b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ trait MtagsEnrichments extends ScalametaCommonEnrichments {
else f(value)
} catch {
// fallback to try without decoding
case _: FileSystemNotFoundException if Properties.isWin =>
case _: NoSuchFileException | _: FileSystemNotFoundException
if Properties.isWin =>
f(value)
// prevents infinity recursion and double check for double escaped %
case _: NoSuchFileException | _: FileSystemNotFoundException
Expand Down
10 changes: 8 additions & 2 deletions tests/mtest/src/main/scala/tests/Assertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ trait Assertions extends munit.Assertions {
def assertContains(string: String, substring: String)(implicit
loc: Location
): Unit = {
assert(string.contains(substring))
assert(
string.contains(substring),
s""""$string" should contain "$substring""""
)
}

def assertNotContains(string: String, substring: String)(implicit
loc: Location
): Unit = {
assert(!string.contains(substring))
assert(
!string.contains(substring),
s""""$string" should not contain "$substring""""
)
}

def assertDiffNotEqual[T](
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/src/test/scala/tests/MetalsEnrichmentsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import java.io.FileOutputStream
import java.nio.file.Files
import java.nio.file.NoSuchFileException
import java.util.zip.ZipOutputStream

import scala.meta.internal.metals.MetalsEnrichments._
Expand Down Expand Up @@ -55,4 +56,16 @@ class MetalsEnrichmentsSuite extends BaseSuite {
}
}

if (isWindows) {
test("encode-decode-at") {
val uri =
"jar:file%3A///C%3A/Users/niander/scoop/persist/coursier/cache/https/myproj%2540myorg.pkgs.visualstudio.com/myproj/_packaging/MyMavenFeed/maven/v1/com/azure/azure-security-keyvault-certificates/4.6.3/azure-security-keyvault-certificates-4.6.3-sources.jar%21/com/azure/security/keyvault/certificates/CertificateClient.java"
try {
uri.toAbsolutePath
} catch {
case e: NoSuchFileException => assertNotContains(e.getMessage(), "@")
}
}
}

}

0 comments on commit cd4a18b

Please sign in to comment.