mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Ensure _.isFinite returns false for non-numeric strings. [closes #98]
Former-commit-id: 2505c8d7d9a0ab1e5f669730c318efdc9232799b
This commit is contained in:
@@ -89,6 +89,7 @@
|
||||
var nativeBind = reNative.test(nativeBind = slice.bind) && nativeBind,
|
||||
nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray,
|
||||
nativeIsFinite = window.isFinite,
|
||||
nativeIsNaN = window.isNaN,
|
||||
nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys,
|
||||
nativeMax = Math.max,
|
||||
nativeMin = Math.min,
|
||||
@@ -1337,7 +1338,7 @@
|
||||
* // => false
|
||||
*/
|
||||
function isFinite(value) {
|
||||
return nativeIsFinite(value ? +value : parseFloat(value));
|
||||
return nativeIsFinite(value) && !nativeIsNaN(parseFloat(value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
21
test/test.js
21
test/test.js
@@ -774,6 +774,27 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.isFinite');
|
||||
|
||||
(function() {
|
||||
test('should return `false` for non-numeric values', function() {
|
||||
equal(_.isFinite(null), false);
|
||||
equal(_.isFinite([]), false);
|
||||
equal(_.isFinite(true), false);
|
||||
equal(_.isFinite(''), false);
|
||||
equal(_.isFinite(' '), false);
|
||||
equal(_.isFinite('2px'), false);
|
||||
});
|
||||
|
||||
test('should return `true` for numeric string values', function() {
|
||||
equal(_.isFinite('2'), true);
|
||||
equal(_.isFinite('0'), true);
|
||||
equal(_.isFinite('08'), true);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.isObject');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user