-
Notifications
You must be signed in to change notification settings - Fork 32
fix(number validation): Don't target NaN, Infinity, -Infinity, or > 2^53 #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@Test | ||
public void gtMatchConditionEvaluatesNullWithInvalidAttr() throws Exception { | ||
BigInteger bigInteger = new BigInteger("33221312312312312"); | ||
Double infiniteDouble = 1.2/0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this evaluates to NaN
, not infinity. It's probably cleaner use Double.NaN
, Double.POSITIVE_INFINITY
, and Double.NEGATIVE_INFINITY
where needed
@@ -72,6 +70,16 @@ else if (conditionValue instanceof Boolean) { | |||
return new MatchType(matchType, new NullMatch()); | |||
} | |||
|
|||
private static boolean isValidNumber(Object conditionValue) { | |||
if (conditionValue instanceof Integer || conditionValue instanceof Double) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If conditionValue instanceof Integer
, can we also add a restriction that Math.abs(value) <= 1e53
? Technically it's unnecessary since Java ints can't be that large, but since this is a reference SDK, it might be helpful to set an example for other SDKs.
Pull Request Test Coverage Report for Build 722
💛 - Coveralls |
…assertions to check infinite and NAN double
@msohailhussain do you know when you might be able to merge this? @mikeng13 it might be nice to get this into the first official 3.0 release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor suggestion to simplify statements
return true; | ||
} else if (conditionValue instanceof Double) { | ||
Double value = ((Number) conditionValue).doubleValue(); | ||
if (value.isNaN() || value.isInfinite()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (value.isNaN() || value.isInfinite()) { | |
return !(value.isNaN() || value.isInfinite()); |
@@ -72,6 +70,21 @@ else if (conditionValue instanceof Boolean) { | |||
return new MatchType(matchType, new NullMatch()); | |||
} | |||
|
|||
private static boolean isValidNumber(Object conditionValue) { | |||
if (conditionValue instanceof Integer) { | |||
if (Math.abs((Integer) conditionValue) > 1e53) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Math.abs((Integer) conditionValue) > 1e53) { | |
return Math.abs((Integer) conditionValue) <= 1e53; |
No description provided.