diff --git a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt index d73a1811c447..bf263c657c6e 100644 --- a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt +++ b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt @@ -91,6 +91,23 @@ object EelPathUtils { } } + /** If [path] is `\\wsl.localhost\Ubuntu\mnt\c\Program Files`, then actual path is `C:\Program Files` */ + @JvmStatic + fun getActualPath(path: Path): Path = path.run { + if ( + isAbsolute && + nameCount >= 2 && + getName(0).toString() == "mnt" && + getName(1).toString().run { length == 1 && first().isLetter() } + ) + asSequence() + .drop(2) + .map(Path::toString) + .fold(fileSystem.getPath("${getName(1).toString().uppercase()}:\\"), Path::resolve) + else + this + } + /** * ```kotlin * getUriLocalToEel(Path.of("\\\\wsl.localhost\\Ubuntu\\home\\user\\dir")).toString() = "file:/home/user/dir" diff --git a/platform/platform-impl/src/com/intellij/execution/wsl/ijent/nio/IjentWslNioPath.kt b/platform/platform-impl/src/com/intellij/execution/wsl/ijent/nio/IjentWslNioPath.kt index 448285780ddc..9c9dd7024e83 100644 --- a/platform/platform-impl/src/com/intellij/execution/wsl/ijent/nio/IjentWslNioPath.kt +++ b/platform/platform-impl/src/com/intellij/execution/wsl/ijent/nio/IjentWslNioPath.kt @@ -2,6 +2,7 @@ package com.intellij.execution.wsl.ijent.nio import com.intellij.platform.core.nio.fs.BasicFileAttributesHolder2 +import com.intellij.platform.eel.provider.utils.EelPathUtils.getActualPath import java.net.URI import java.nio.file.* @@ -19,21 +20,7 @@ class IjentWslNioPath( require(presentablePath !is IjentWslNioPath) { "IjentWslNioPath should be a wrapper over other instances of path, namely WindowsPath or IjentNioPath" } } - /** If [presentablePath] is `\\wsl.localhost\Ubuntu\mnt\c\Program Files`, then [actualPath] is `C:\Program Files` */ - val actualPath: Path = presentablePath.run { - if ( - isAbsolute && - nameCount >= 2 && - getName(0).toString() == "mnt" && - getName(1).toString().run { length == 1 && first().isLetter() } - ) - asSequence() - .drop(2) - .map(Path::toString) - .fold(fileSystem.getPath("${getName(1).toString().uppercase()}:\\"), Path::resolve) - else - this - } + val actualPath: Path = getActualPath(presentablePath) override fun getFileSystem(): IjentWslNioFileSystem = fileSystem diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEelUtil.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEelUtil.kt index 94de17318788..b73a86af2844 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEelUtil.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEelUtil.kt @@ -38,6 +38,7 @@ import com.intellij.platform.eel.fs.getPath import com.intellij.platform.eel.provider.asNioPath import com.intellij.platform.eel.provider.asNioPathOrNull import com.intellij.platform.eel.provider.getEelDescriptor +import com.intellij.platform.eel.provider.utils.EelPathUtils.getActualPath import com.intellij.platform.eel.provider.utils.fetchLoginShellEnvVariablesBlocking import com.intellij.platform.eel.provider.utils.where import com.intellij.platform.ide.progress.runWithModalProgressBlocking @@ -492,6 +493,10 @@ object MavenEelUtil { } private fun EelFileSystemApi.tryMavenRoot(path: String): MavenInSpecificPath? { + // we want to prevent paths like "\\wsl.localhost\Ubuntu\mnt\c\Something\something" from being leaked into the execution + if (!path.isActualPathString()) { + return null + } val home = getPath(path).asNioPath() if (isValidMavenHome(home)) { MavenLog.LOG.debug("Maven home found at $path") @@ -499,4 +504,9 @@ object MavenEelUtil { } return null } + + private fun String.isActualPathString(): Boolean { + val path = Path.of(this) + return path == getActualPath(path) + } } \ No newline at end of file