From 7317a5c4810f50bdb6e80d313de8134ba95695de Mon Sep 17 00:00:00 2001 From: owent <> Date: Wed, 4 Sep 2024 15:49:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B4=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=AA=8C=E8=AF=81=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=B5=AE=E7=82=B9=E6=95=B0=E8=BD=AC=E6=95=B4?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HISTORY.md | 2 ++ .../xresloader/core/data/vfy/DataVerifyImpl.java | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 8eb7fd6b..ec2c7db1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,8 @@ ## Unrelease +1. 优化整数类型的验证,不允许浮点数转整数 + ## 2.18.2 1. 修复 2.18.0-2.18.1 版本中映射可选字段的错误。 diff --git a/src/org/xresloader/core/data/vfy/DataVerifyImpl.java b/src/org/xresloader/core/data/vfy/DataVerifyImpl.java index 1663eb1f..9d6701d1 100644 --- a/src/org/xresloader/core/data/vfy/DataVerifyImpl.java +++ b/src/org/xresloader/core/data/vfy/DataVerifyImpl.java @@ -358,7 +358,18 @@ static public String getAndVerifyToString(List verifyEngine, Str static public long getAndVerifyToLong(List verifyEngine, String path, String val) throws ConvException { - return Math.round(getAndVerifyToDouble(verifyEngine, path, val)); + double value = getAndVerifyToDouble(verifyEngine, path, val); + long ret = Math.round(value); + if (Math.abs(value - (double) ret) > 1e-6) { + String message = String.format("Convert %s for %s with %s %s failed, not a integer.", val, + path, getValidatorWord(verifyEngine), collectValidatorNames(verifyEngine)); + if (ProgramOptions.getInstance().enableDataValidator) { + throw new ConvException(message); + } else { + ProgramOptions.getLoger().warn(message); + } + } + return ret; } static public class ValidatorTokens { From f32f01856c01debdd857fda14e39dcb98d0de4cd Mon Sep 17 00:00:00 2001 From: owent <> Date: Wed, 4 Sep 2024 16:10:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E8=AE=A2=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=83=85=E5=86=B5=E7=9A=84=E9=94=99=E8=AF=AF=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/vfy/DataVerifyImpl.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/org/xresloader/core/data/vfy/DataVerifyImpl.java b/src/org/xresloader/core/data/vfy/DataVerifyImpl.java index 9d6701d1..01485198 100644 --- a/src/org/xresloader/core/data/vfy/DataVerifyImpl.java +++ b/src/org/xresloader/core/data/vfy/DataVerifyImpl.java @@ -296,8 +296,14 @@ static public double getAndVerifyToDouble(List verifyEngine, Str } } - String message = String.format("Convert %s for %s with %s %s failed, check data failed.", val, - path, getValidatorWord(verifyEngine), collectValidatorNames(verifyEngine)); + String message; + if (verifyEngine == null || verifyEngine.isEmpty()) { + message = String.format("Convert %s for %s, check data failed.", val, + path); + } else { + message = String.format("Convert %s for %s with %s %s failed, check data failed.", val, + path, getValidatorWord(verifyEngine), collectValidatorNames(verifyEngine)); + } if (ProgramOptions.getInstance().enableDataValidator) { throw new ConvException(message); } else { @@ -346,8 +352,14 @@ static public String getAndVerifyToString(List verifyEngine, Str } } - String message = String.format("Convert %s for %s with %s %s failed, check data failed.", val, - path, getValidatorWord(verifyEngine), collectValidatorNames(verifyEngine)); + String message; + if (verifyEngine == null || verifyEngine.isEmpty()) { + message = String.format("Convert %s for %s failed, check data failed.", val, + path); + } else { + message = String.format("Convert %s for %s with %s %s failed, check data failed.", val, + path, getValidatorWord(verifyEngine), collectValidatorNames(verifyEngine)); + } if (ProgramOptions.getInstance().enableDataValidator) { throw new ConvException(message); } else { @@ -361,8 +373,14 @@ static public long getAndVerifyToLong(List verifyEngine, String double value = getAndVerifyToDouble(verifyEngine, path, val); long ret = Math.round(value); if (Math.abs(value - (double) ret) > 1e-6) { - String message = String.format("Convert %s for %s with %s %s failed, not a integer.", val, - path, getValidatorWord(verifyEngine), collectValidatorNames(verifyEngine)); + String message; + if (verifyEngine == null || verifyEngine.isEmpty()) { + message = String.format("Convert %s for %s failed, not a integer.", val, + path); + } else { + message = String.format("Convert %s for %s with %s %s failed, not a integer.", val, + path, getValidatorWord(verifyEngine), collectValidatorNames(verifyEngine)); + } if (ProgramOptions.getInstance().enableDataValidator) { throw new ConvException(message); } else {