Skip to content
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

Fix isInteger for unsafe integers #203

Merged
merged 1 commit into from Mar 31, 2017
Merged

Fix isInteger for unsafe integers #203

merged 1 commit into from Mar 31, 2017

Conversation

@Marsup
Copy link
Member

Marsup commented Mar 31, 2017

Relates to hapijs/joi#1143.

I removed the isNaN check because it was already checked by the previous line NaN !== NaN.

@Marsup Marsup added the bug label Mar 31, 2017
@Marsup Marsup requested a review from nlf Mar 31, 2017
@@ -882,7 +882,7 @@ exports.isInteger = function (value) {

return (typeof value === 'number' &&
parseFloat(value) === parseInt(value, 10) &&

This comment has been minimized.

Copy link
@kanongil

kanongil Mar 31, 2017

Member

This line can be omitted as well, as only integers will pass the Number.isSafeInteger() test.

This comment has been minimized.

Copy link
@nlf

nlf Mar 31, 2017

Member

do we actually need anything other than Number.isSafeInteger? it returns false for any input that isn't a number too, so i'm pretty sure exports.isInteger = Number.isSafeInteger would be just as effective

This comment has been minimized.

Copy link
@Marsup

Marsup Mar 31, 2017

Author Member

Good spot indeed !

This comment has been minimized.

Copy link
@Marsup

Marsup Mar 31, 2017

Author Member

OK, let's go for that then !

@Marsup Marsup force-pushed the fix-isInteger branch from bba585a to fe3e3eb Mar 31, 2017
@kanongil

This comment has been minimized.

Copy link
Member

kanongil commented Mar 31, 2017

In reality, this should just be dropped from the api with the next breaking release.

And Joi might as well just use Number.isSafeInteger() directly.

@nlf

This comment has been minimized.

Copy link
Member

nlf commented Mar 31, 2017

i agree. for now it'll be a patch release making it an alias for Number.isSafeInteger, next major of hoek will remove it completely

@Marsup

This comment has been minimized.

Copy link
Member Author

Marsup commented Mar 31, 2017

Makes sense for joi, not sure how it'll be received by Eran though, considering all the aliases to node core function hoek still contains.

@nlf

This comment has been minimized.

Copy link
Member

nlf commented Mar 31, 2017

we should probably start chipping away at those

@nlf nlf merged commit 7666fa4 into master Mar 31, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@nlf nlf self-assigned this Mar 31, 2017
@nlf nlf added this to the 4.1.1 milestone Mar 31, 2017
@Marsup

This comment has been minimized.

Copy link
Member Author

Marsup commented Mar 31, 2017

FWIW I tried it in hapi, it didn't seem to break any test there either.

@Marsup Marsup deleted the fix-isInteger branch Mar 31, 2017
@hueniverse

This comment has been minimized.

Copy link
Member

hueniverse commented Apr 2, 2017

I'm all for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.