Browse Source
Merge pull request #11969 from thingsboard/fix_bug_tbel_valuidate_numeric
tbel_fix_bug_validate_decimal
pull/11976/head
Andrew Shvayka
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
2 additions and
1 deletions
-
common/script/script-api/src/main/java/org/thingsboard/script/api/tbel/TbUtils.java
-
common/script/script-api/src/test/java/org/thingsboard/script/api/tbel/TbUtilsTest.java
|
|
|
@ -1255,7 +1255,7 @@ public class TbUtils { |
|
|
|
if (str == null || str.isEmpty()) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
return str.matches("-?\\d+(\\.\\d+)?") ? DEC_RADIX : -1; |
|
|
|
return str.matches("[+-]?\\d+(\\.\\d+)?") ? DEC_RADIX : -1; |
|
|
|
} |
|
|
|
|
|
|
|
public static int isHexadecimal(String str) { |
|
|
|
|
|
|
|
@ -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(java.util.Optional.of(473).get(), TbUtils.parseInt("473")); |
|
|
|
Assertions.assertEquals(java.util.Optional.of(-255).get(), TbUtils.parseInt("-0xFF")); |
|
|
|
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("-0xFF123")); |
|
|
|
|