mirror of
https://gitee.com/dromara/hutool.git
synced 2025-11-24 08:33:22 +08:00
Merge pull request #4142 from ZhonglinGui/v5-dev
修复FileNameUtil.extName 方法对特殊后缀判断逻辑过于宽松导致误判
This commit is contained in:
@@ -238,7 +238,7 @@ public class FileNameUtil {
|
||||
// issue#I4W5FS@Gitee
|
||||
final int secondToLastIndex = fileName.substring(0, index).lastIndexOf(StrUtil.DOT);
|
||||
final String substr = fileName.substring(secondToLastIndex == -1 ? index : secondToLastIndex + 1);
|
||||
if (StrUtil.containsAny(substr, SPECIAL_SUFFIX)) {
|
||||
if (StrUtil.equalsAny(substr, SPECIAL_SUFFIX)) {
|
||||
return substr;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,12 @@ public class FileNameUtilTest {
|
||||
final String s = FileNameUtil.mainName("abc.tar.gz");
|
||||
assertEquals("abc", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extNameAndMainNameBugTest() {
|
||||
// 正确,输出前缀为 "app-v2.3.1-star"
|
||||
assertEquals("app-v2.3.1-star",FileNameUtil.mainName("app-v2.3.1-star.gz"));
|
||||
// 当前代码会失败,预期后缀结果 "gz",但是输出 "star.gz"
|
||||
assertEquals("gz", FileNameUtil.extName("app-v2.3.1-star.gz"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user