mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复HexUtil.isHexNumber()对"-"的判断问题
This commit is contained in:
parent
09a2dc3807
commit
a0cba2fd55
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.8.12.M1 (2022-12-27)
|
# 5.8.12.M1 (2023-01-15)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
* 【core 】 修复HexUtil.isHexNumber()对"-"的判断问题(issue#2857@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -27,7 +27,11 @@ public class HexUtil {
|
|||||||
* @return 是否为16进制
|
* @return 是否为16进制
|
||||||
*/
|
*/
|
||||||
public static boolean isHexNumber(String value) {
|
public static boolean isHexNumber(String value) {
|
||||||
int index = (value.startsWith("-") ? 1 : 0);
|
if(StrUtil.startWith(value, '-')){
|
||||||
|
// issue#2875
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int index = 0;
|
||||||
if (value.startsWith("0x", index) || value.startsWith("0X", index)) {
|
if (value.startsWith("0x", index) || value.startsWith("0X", index)) {
|
||||||
index += 2;
|
index += 2;
|
||||||
} else if (value.startsWith("#", index)) {
|
} else if (value.startsWith("#", index)) {
|
||||||
|
@ -49,6 +49,10 @@ public class HexUtilTest {
|
|||||||
// 错误的
|
// 错误的
|
||||||
a = "0x0000001000T00001158e460913d00000";
|
a = "0x0000001000T00001158e460913d00000";
|
||||||
Assert.assertFalse(HexUtil.isHexNumber(a));
|
Assert.assertFalse(HexUtil.isHexNumber(a));
|
||||||
|
|
||||||
|
// 错误的,https://github.com/dromara/hutool/issues/2857
|
||||||
|
a = "-1";
|
||||||
|
Assert.assertFalse(HexUtil.isHexNumber(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user