From b708b01a7d3e6b3f0d47b36d9e19fb6a0c64a890 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 11 Aug 2023 20:24:30 +0300 Subject: [PATCH] Python path validation should support `\\wsl` paths on Windows. On Windows user may create project in `\\wsl` GitOrigin-RevId: 593ecf6440394df6d3034b1ea630c262b6ff26c2 --- .../python/pathValidation/PathValidator.kt | 3 +- .../python/tests/ValidationRequestTest.kt | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 python/python-sdk/tests/com/jetbrains/python/tests/ValidationRequestTest.kt diff --git a/python/python-sdk/src/com/jetbrains/python/pathValidation/PathValidator.kt b/python/python-sdk/src/com/jetbrains/python/pathValidation/PathValidator.kt index 750a350b75b4..1401d9c4eeb2 100644 --- a/python/python-sdk/src/com/jetbrains/python/pathValidation/PathValidator.kt +++ b/python/python-sdk/src/com/jetbrains/python/pathValidation/PathValidator.kt @@ -52,7 +52,8 @@ class ValidationRequest(@NonNls internal val path: String?, private fun isAbsolutePath(path: String): Boolean = when (platformAndRoot.platform) { Platform.UNIX -> path.startsWith("/") - Platform.WINDOWS -> OSAgnosticPathUtil.isAbsoluteDosPath(path) + // On Windows user may create project in \\wsl + Platform.WINDOWS -> OSAgnosticPathUtil.isAbsoluteDosPath(path) || path.startsWith("\\\\wsl") } } diff --git a/python/python-sdk/tests/com/jetbrains/python/tests/ValidationRequestTest.kt b/python/python-sdk/tests/com/jetbrains/python/tests/ValidationRequestTest.kt new file mode 100644 index 000000000000..fdf0f5f411f8 --- /dev/null +++ b/python/python-sdk/tests/com/jetbrains/python/tests/ValidationRequestTest.kt @@ -0,0 +1,29 @@ +package com.jetbrains.python.tests + +import com.intellij.execution.Platform +import com.jetbrains.python.pathValidation.PlatformAndRoot +import com.jetbrains.python.pathValidation.ValidationRequest +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Test + +class ValidationRequestTest { + + @Test + fun testAbsolutePath() { + if (PlatformAndRoot.local.platform == Platform.UNIX) { + assertNull("No error must be returned", + ValidationRequest("/", "", PlatformAndRoot.local, null).validate { null }) + assertNotNull("Path not absolute, but no error returned", + ValidationRequest("abc", "", PlatformAndRoot.local, null).validate { null }) + } + else { + assertNull("No error must be returned", + ValidationRequest("\\\\wsl$\\asdad", "", PlatformAndRoot.local, null).validate { null }) + assertNull("No error must be returned", + ValidationRequest("c:\\", "", PlatformAndRoot.local, null).validate { null }) + assertNotNull("Path not absolute, but no error returned", + ValidationRequest("abc", "", PlatformAndRoot.local, null).validate { null }) + } + } +} \ No newline at end of file