Merge pull request #11969 from thingsboard/fix_bug_tbel_valuidate_numeric

tbel_fix_bug_validate_decimal
This commit is contained in:
Andrew Shvayka 2024-10-30 12:41:01 +01:00 committed by GitHub
commit 394103a43d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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"));