mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-12-06 17:18:54 +08:00
Merge pull request #4142 from ZhonglinGui/v5-dev
修复FileNameUtil.extName 方法对特殊后缀判断逻辑过于宽松导致误判
This commit is contained in:
commit
c6cbaeabff
@ -238,7 +238,7 @@ public class FileNameUtil {
|
|||||||
// issue#I4W5FS@Gitee
|
// issue#I4W5FS@Gitee
|
||||||
final int secondToLastIndex = fileName.substring(0, index).lastIndexOf(StrUtil.DOT);
|
final int secondToLastIndex = fileName.substring(0, index).lastIndexOf(StrUtil.DOT);
|
||||||
final String substr = fileName.substring(secondToLastIndex == -1 ? index : secondToLastIndex + 1);
|
final String substr = fileName.substring(secondToLastIndex == -1 ? index : secondToLastIndex + 1);
|
||||||
if (StrUtil.containsAny(substr, SPECIAL_SUFFIX)) {
|
if (StrUtil.equalsAny(substr, SPECIAL_SUFFIX)) {
|
||||||
return substr;
|
return substr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,4 +19,12 @@ public class FileNameUtilTest {
|
|||||||
final String s = FileNameUtil.mainName("abc.tar.gz");
|
final String s = FileNameUtil.mainName("abc.tar.gz");
|
||||||
assertEquals("abc", s);
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user