Skip to content

Commit 77cdc21

Browse files
authored
在非 Windows 平台也将 : 视为非法字符 (#5035)
1 parent cc092f5 commit 77cdc21

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/FileUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public static boolean isNameValid(OperatingSystem os, String name) {
177177
if (!Character.isValidCodePoint(codePoint)
178178
|| Character.isISOControl(codePoint)
179179
|| codePoint == '/' || codePoint == '\0'
180+
|| codePoint == ':'
180181
// Unicode replacement character
181182
|| codePoint == 0xfffd
182183
// Not Unicode character
@@ -185,7 +186,7 @@ public static boolean isNameValid(OperatingSystem os, String name) {
185186

186187
// https://learn.microsoft.com/windows/win32/fileio/naming-a-file
187188
if (os == OperatingSystem.WINDOWS &&
188-
(ch == '<' || ch == '>' || ch == ':' || ch == '"' || ch == '\\' || ch == '|' || ch == '?' || ch == '*')) {
189+
(ch == '<' || ch == '>' || ch == '"' || ch == '\\' || ch == '|' || ch == '?' || ch == '*')) {
189190
return false;
190191
}
191192
}

HMCLCore/src/test/java/org/jackhuang/hmcl/util/io/FileUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void testIsNameValid(OperatingSystem os) {
5252
assertFalse(FileUtils.isNameValid(os, "a\uD83Db"));
5353
assertFalse(FileUtils.isNameValid(os, "a\uDE00b"));
5454
assertFalse(FileUtils.isNameValid(os, "a\uDE00\uD83Db"));
55+
assertFalse(FileUtils.isNameValid(os, "f:oo"));
5556

5657
// Platform-specific tests
5758
boolean isWindows = os == OperatingSystem.WINDOWS;
@@ -62,7 +63,6 @@ public void testIsNameValid(OperatingSystem os) {
6263
assertEquals(isNotWindows, FileUtils.isNameValid(os, "foo "));
6364
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f<oo"));
6465
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f>oo"));
65-
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f:oo"));
6666
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f?oo"));
6767
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f*oo"));
6868
assertEquals(isNotWindows, FileUtils.isNameValid(os, "f\\oo"));

0 commit comments

Comments
 (0)