fix issue IDFNHE,增强 CharUtil 类中的 toCloseByNumber(int number) 方法的边界检查。

This commit is contained in:
shad0wm00n
2025-12-25 01:29:09 +08:00
parent de93fa7670
commit bb99a68608
2 changed files with 8 additions and 1 deletions

View File

@@ -385,7 +385,7 @@ public class CharUtil implements CharPool {
* @since 5.6.2
*/
public static char toCloseByNumber(int number) {
if (number > 20) {
if (number < 1 || number > 20) {
throw new IllegalArgumentException("Number must be [1-20]");
}
return (char) ('①' + number - 1);

View File

@@ -71,4 +71,11 @@ public class CharUtilTest {
c = '\u2800';
assertTrue(CharUtil.isBlankChar(c));
}
@Test
public void issueIDFNHETest(){
//Console.log(CharUtil.toCloseByNumber(0)); //此时会打印"⑟"
assertThrows(IllegalArgumentException.class, () -> CharUtil.toCloseByNumber(0));
assertThrows(IllegalArgumentException.class, () -> CharUtil.toCloseByNumber(-1));
}
}