mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-14 04:37:50 +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,
|
var nativeBind = reNative.test(nativeBind = slice.bind) && nativeBind,
|
||||||
nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray,
|
nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray,
|
||||||
nativeIsFinite = window.isFinite,
|
nativeIsFinite = window.isFinite,
|
||||||
|
nativeIsNaN = window.isNaN,
|
||||||
nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys,
|
nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys,
|
||||||
nativeMax = Math.max,
|
nativeMax = Math.max,
|
||||||
nativeMin = Math.min,
|
nativeMin = Math.min,
|
||||||
@@ -1337,7 +1338,7 @@
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isFinite(value) {
|
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');
|
QUnit.module('lodash.isObject');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user