tbel: fix bug validate decimal with <+>

This commit is contained in:
nick 2024-10-29 12:26:12 +02:00
parent 0162158327
commit 6581e48055
2 changed files with 2 additions and 1 deletions

View File

@ -1255,7 +1255,7 @@ public class TbUtils {
if (str == null || str.isEmpty()) { if (str == null || str.isEmpty()) {
return -1; return -1;
} }
return str.matches("-?\\d+(\\.\\d+)?") ? DEC_RADIX : -1; return str.matches("[+-]?\\d+(\\.\\d+)?") ? DEC_RADIX : -1;
} }
public static int isHexadecimal(String str) { public static int isHexadecimal(String str) {

View File

@ -213,6 +213,7 @@ public class TbUtilsTest {
Assertions.assertEquals((Integer) 0, TbUtils.parseInt("0")); Assertions.assertEquals((Integer) 0, TbUtils.parseInt("0"));
Assertions.assertEquals((Integer) 0, TbUtils.parseInt("-0")); Assertions.assertEquals((Integer) 0, TbUtils.parseInt("-0"));
Assertions.assertEquals((Integer) 0, TbUtils.parseInt("+0"));
Assertions.assertEquals(java.util.Optional.of(473).get(), TbUtils.parseInt("473")); Assertions.assertEquals(java.util.Optional.of(473).get(), TbUtils.parseInt("473"));
Assertions.assertEquals(java.util.Optional.of(-255).get(), TbUtils.parseInt("-0xFF")); Assertions.assertEquals(java.util.Optional.of(-255).get(), TbUtils.parseInt("-0xFF"));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("-0xFF123")); Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("-0xFF123"));