mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ensure 3rd char is slash in FileUtil.isWindowsAbsolutePath (IDEA-CR-34321)
This commit is contained in:
@@ -1430,8 +1430,13 @@ public class FileUtil extends FileUtilRt {
|
||||
return path.startsWith("/");
|
||||
}
|
||||
|
||||
public static boolean isWindowsAbsolutePath(@NotNull String pathString) {
|
||||
return pathString.length() >= 2 && Character.isLetter(pathString.charAt(0)) && pathString.charAt(1) == ':';
|
||||
public static boolean isWindowsAbsolutePath(@NotNull String path) {
|
||||
boolean ok = path.length() >= 2 && Character.isLetter(path.charAt(0)) && path.charAt(1) == ':';
|
||||
if (ok && path.length() > 2) {
|
||||
char separatorChar = path.charAt(2);
|
||||
ok = separatorChar == '/' || separatorChar == '\\';
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@Contract("null -> null; !null -> !null")
|
||||
|
||||
@@ -231,4 +231,24 @@ public class FileUtilLightTest {
|
||||
assertFalse(FileUtil.containsWindowsShortName("C:/dir/file.~1"));
|
||||
assertFalse(FileUtil.containsWindowsShortName("C:/dir/file.ext~1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void windowsAbsolutePath() {
|
||||
assertTrue(FileUtil.isWindowsAbsolutePath("C:\\Users"));
|
||||
assertTrue(FileUtil.isWindowsAbsolutePath("C:/Users"));
|
||||
assertTrue(FileUtil.isWindowsAbsolutePath("X:/Users"));
|
||||
assertTrue(FileUtil.isWindowsAbsolutePath("X:/"));
|
||||
assertTrue(FileUtil.isWindowsAbsolutePath("X:"));
|
||||
assertTrue(FileUtil.isWindowsAbsolutePath("X:\\"));
|
||||
assertTrue(FileUtil.isWindowsAbsolutePath("X:\\Users\\user.data.txt"));
|
||||
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath(""));
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath("/"));
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath("/home"));
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath("C"));
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath("1"));
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath("1:"));
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath("C:C"));
|
||||
assertFalse(FileUtil.isWindowsAbsolutePath("C?"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user