mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
针对issue#I4W5FS@Gitee存在其他特殊情况处理
This commit is contained in:
parent
ae8849c665
commit
919dbca570
@ -42,6 +42,11 @@ public class FileNameUtil {
|
|||||||
*/
|
*/
|
||||||
private static final Pattern FILE_NAME_INVALID_PATTERN_WIN = Pattern.compile("[\\\\/:*?\"<>|]");
|
private static final Pattern FILE_NAME_INVALID_PATTERN_WIN = Pattern.compile("[\\\\/:*?\"<>|]");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 特殊后缀
|
||||||
|
*/
|
||||||
|
private static final CharSequence[] SPECIAL_SUFFIX = {"tar.bz2", "tar.Z", "tar.gz"};
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------- name start
|
// -------------------------------------------------------------------------------------------- name start
|
||||||
|
|
||||||
@ -223,8 +228,10 @@ public class FileNameUtil {
|
|||||||
return StrUtil.EMPTY;
|
return StrUtil.EMPTY;
|
||||||
} else {
|
} else {
|
||||||
// issue#I4W5FS@Gitee
|
// issue#I4W5FS@Gitee
|
||||||
if(fileName.endsWith("tar.gz")){
|
int secondToLastIndex = fileName.substring(0, index).lastIndexOf(StrUtil.DOT);
|
||||||
return "tar.gz";
|
String substr = fileName.substring(secondToLastIndex == -1 ? index : secondToLastIndex + 1);
|
||||||
|
if (StrUtil.containsAny(substr, SPECIAL_SUFFIX)) {
|
||||||
|
return substr;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ext = fileName.substring(index + 1);
|
String ext = fileName.substring(index + 1);
|
||||||
|
@ -396,6 +396,14 @@ public class FileUtilTest {
|
|||||||
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.gz" : "~/Desktop/hutool/fff.tar.gz";
|
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.gz" : "~/Desktop/hutool/fff.tar.gz";
|
||||||
mainName = FileUtil.extName(path);
|
mainName = FileUtil.extName(path);
|
||||||
Assert.assertEquals("tar.gz", mainName);
|
Assert.assertEquals("tar.gz", mainName);
|
||||||
|
|
||||||
|
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.Z" : "~/Desktop/hutool/fff.tar.Z";
|
||||||
|
mainName = FileUtil.extName(path);
|
||||||
|
Assert.assertEquals("tar.Z", mainName);
|
||||||
|
|
||||||
|
path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.bz2" : "~/Desktop/hutool/fff.tar.bz2";
|
||||||
|
mainName = FileUtil.extName(path);
|
||||||
|
Assert.assertEquals("tar.bz2", mainName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user