-
Notifications
You must be signed in to change notification settings - Fork 83
feat(attribute_value): Don't target NAN, INF, -INF and > 2^53. #204
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
packages/optimizely-sdk/lib/core/custom_attribute_condition_evaluator/index.tests.js
Show resolved
Hide resolved
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.
Code looks good, but I think we could test isFinite
a little more directly! There are several values we need to test
@@ -24,7 +25,9 @@ module.exports = { | |||
}, | |||
isArray: require('lodash/isArray'), | |||
isEmpty: require('lodash/isEmpty'), | |||
isFinite: require('lodash/isFinite'), | |||
isFinite: function(number) { | |||
return finite(number) && Math.abs(number) <= Math.pow(2, 53); |
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.
return finite(number) && Math.abs(number) <= Math.pow(2, 53); | |
return finite(number) && Math.abs(number) <= Number.MAX_SAFE_INTEGER + 1; |
packages/optimizely-sdk/lib/core/custom_attribute_condition_evaluator/index.tests.js
Show resolved
Hide resolved
'boolean_key': false, | ||
'browser_type': Infinity, | ||
'integer_key': NaN, | ||
'boolean_key': (Math.pow(2, 53) + 2) * -1, | ||
'double_key': [1, 2, 3], |
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.
Nit: strange attribute keys 🤔
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.
I think we should continue including some valid attributes so that we can make sure they're kept even when other attributes are filtered out? For example
'browser_type': 'Chrome',
'valid_positive_number': Math.pow(2, 53),
'valid_negative_number': -Math.pow(2, 53),
'invalid_number': Math.pow(2, 53) + 2,
'array': [1, 2, 3]
and then assert that only the first three are accepted
'browser_type': -Infinity, | ||
'integer_key': NaN, | ||
'boolean_key': Math.pow(2, 53) + 2, | ||
'double_key': [1, 2, 3], |
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.
Same suggestion - we should include some valid attribute values too
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.
Looks great. Thanks for updating!
Summary
Don't target NAN, INF or -INF doubles
Don't target Values > 2^53.
Modified fns.isFinite to check if the number is greater than 2^53.
Test plan
Issues