Commit 21419c7b91928a7f70a491e57a4a07f1950f8c96

Authored by zhengshouren
1 parent 87cc3a35

非法数字判定更严格,防止空值报错,防止1.0这样的浮点数通过验证

Showing 1 changed file with 8 additions and 7 deletions   Show diff stats
src/utils/MathUtil.lua
@@ -42,6 +42,9 @@ function math.randWeight(dataset, field) @@ -42,6 +42,9 @@ function math.randWeight(dataset, field)
42 end 42 end
43 43
44 function math.illegalNum(num, min, max) 44 function math.illegalNum(num, min, max)
  45 + if num == nil then
  46 + return true
  47 + end
45 if type(num) ~= "number" then 48 if type(num) ~= "number" then
46 -- 非数字类型 49 -- 非数字类型
47 return true 50 return true
@@ -54,14 +57,12 @@ function math.illegalNum(num, min, max) @@ -54,14 +57,12 @@ function math.illegalNum(num, min, max)
54 -- 非整数 57 -- 非整数
55 return true 58 return true
56 end 59 end
57 - if math.abs(max - min) > 1000 then  
58 - -- 防止出现数值过大的情况,在线上环境出现效率问题 60 + if num < min or num > max then
59 return true 61 return true
60 end 62 end
61 - for i = min, max do  
62 - if num == i then  
63 - return false  
64 - end 63 + if string.find(tostring(num), '%.') then
  64 + -- 确保不会出现类似1.0这样的数据
  65 + return true
65 end 66 end
66 - return true 67 + return false
67 end 68 end
68 \ No newline at end of file 69 \ No newline at end of file