Merge pull request #11969 from thingsboard/fix_bug_tbel_valuidate_numeric
tbel_fix_bug_validate_decimal
This commit is contained in:
commit
394103a43d
@ -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) {
|
||||||
|
|||||||
@ -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"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user