在非 Windows 平台也将 : 视为非法字符 (#5035)
This commit is contained in:
@@ -177,6 +177,7 @@ public final class FileUtils {
|
||||
if (!Character.isValidCodePoint(codePoint)
|
||||
|| Character.isISOControl(codePoint)
|
||||
|| codePoint == '/' || codePoint == '\0'
|
||||
|| codePoint == ':'
|
||||
// Unicode replacement character
|
||||
|| codePoint == 0xfffd
|
||||
// Not Unicode character
|
||||
@@ -185,7 +186,7 @@ public final class FileUtils {
|
||||
|
||||
// https://learn.microsoft.com/windows/win32/fileio/naming-a-file
|
||||
if (os == OperatingSystem.WINDOWS &&
|
||||
(ch == '<' || ch == '>' || ch == ':' || ch == '"' || ch == '\\' || ch == '|' || ch == '?' || ch == '*')) {
|
||||
(ch == '<' || ch == '>' || ch == '"' || ch == '\\' || ch == '|' || ch == '?' || ch == '*')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class FileUtilsTest {
|
||||
assertFalse(FileUtils.isNameValid(os, "a\uD83Db"));
|
||||
assertFalse(FileUtils.isNameValid(os, "a\uDE00b"));
|
||||
assertFalse(FileUtils.isNameValid(os, "a\uDE00\uD83Db"));
|
||||
assertFalse(FileUtils.isNameValid(os, "f:oo"));
|
||||
|
||||
// Platform-specific tests
|
||||
boolean isWindows = os == OperatingSystem.WINDOWS;
|
||||
@@ -62,7 +63,6 @@ public class FileUtilsTest {
|
||||
assertEquals(isNotWindows, FileUtils.isNameValid(os, "foo "));
|
||||
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f<oo"));
|
||||
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f>oo"));
|
||||
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f:oo"));
|
||||
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f?oo"));
|
||||
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f*oo"));
|
||||
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f\\oo"));
|
||||
|
||||
Reference in New Issue
Block a user