Skip to content

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

Merged
merged 5 commits into from
Jan 8, 2019

Conversation

mfahadahmed
Copy link
Contributor

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

@coveralls
Copy link

coveralls commented Dec 26, 2018

Coverage Status

Coverage increased (+0.02%) to 97.262% when pulling 469cc3d on fahad/invalid-numeric-value into d33e2cb on master.

Copy link
Contributor

@nchilada nchilada left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return finite(number) && Math.abs(number) <= Math.pow(2, 53);
return finite(number) && Math.abs(number) <= Number.MAX_SAFE_INTEGER + 1;

'boolean_key': false,
'browser_type': Infinity,
'integer_key': NaN,
'boolean_key': (Math.pow(2, 53) + 2) * -1,
'double_key': [1, 2, 3],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: strange attribute keys 🤔

Copy link
Contributor

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],
Copy link
Contributor

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

Copy link
Contributor

@nchilada nchilada left a 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!

@mikeproeng37 mikeproeng37 merged commit 7fe2e0e into master Jan 8, 2019
@mfahadahmed mfahadahmed deleted the fahad/invalid-numeric-value branch January 11, 2019 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants