mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Ensure that when we check typeof x == 'number' we also check instanceof Number (#5752)
This commit is contained in:
parent
81b4b87666
commit
b3b5c7de4f
@ -42,7 +42,7 @@ function interpolate(start, view, model, ease) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (type === 'number' && isFinite(origin) && isFinite(target)) {
|
||||
} else if (helpers.isFinite(origin) && helpers.isFinite(target)) {
|
||||
view[key] = origin + (target - origin) * ease;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -519,7 +519,7 @@ module.exports = Element.extend({
|
||||
return NaN;
|
||||
}
|
||||
// isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
|
||||
if (typeof rawValue === 'number' && !isFinite(rawValue)) {
|
||||
if ((typeof rawValue === 'number' || rawValue instanceof Number) && !isFinite(rawValue)) {
|
||||
return NaN;
|
||||
}
|
||||
// If it is in fact an object, dive in one more level
|
||||
|
||||
@ -51,6 +51,15 @@ var helpers = {
|
||||
return value !== null && Object.prototype.toString.call(value) === '[object Object]';
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if `value` is a finite number, else returns false
|
||||
* @param {*} value - The value to test.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isFinite: function(value) {
|
||||
return (typeof value === 'number' || value instanceof Number) && isFinite(value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns `value` if defined, else returns `defaultValue`.
|
||||
* @param {*} value - The value to return if defined.
|
||||
|
||||
@ -128,7 +128,7 @@ function computeBoundary(source) {
|
||||
return target;
|
||||
}
|
||||
|
||||
if (typeof target === 'number' && isFinite(target)) {
|
||||
if (helpers.isFinite(target)) {
|
||||
horizontal = scale.isHorizontal();
|
||||
return {
|
||||
x: horizontal ? target : null,
|
||||
|
||||
@ -56,6 +56,24 @@ describe('Chart.helpers.core', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isFinite', function() {
|
||||
it('should return true if value is a finite number', function() {
|
||||
expect(helpers.isFinite(0)).toBeTruthy();
|
||||
// eslint-disable-next-line no-new-wrappers
|
||||
expect(helpers.isFinite(new Number(10))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return false if the value is infinite', function() {
|
||||
expect(helpers.isFinite(Number.POSITIVE_INFINITY)).toBeFalsy();
|
||||
expect(helpers.isFinite(Number.NEGATIVE_INFINITY)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return false if the value is not a number', function() {
|
||||
expect(helpers.isFinite('a')).toBeFalsy();
|
||||
expect(helpers.isFinite({})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNullOrUndef', function() {
|
||||
it('should return true if value is null/undefined', function() {
|
||||
expect(helpers.isNullOrUndef(null)).toBeTruthy();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user