diff --git a/src/core/friendly_errors/validate_params.js b/src/core/friendly_errors/validate_params.js index 9e153fb47a..2fb9054d97 100644 --- a/src/core/friendly_errors/validate_params.js +++ b/src/core/friendly_errors/validate_params.js @@ -344,9 +344,9 @@ if (typeof IS_MINIFIED !== 'undefined') { const isNumber = param => { switch (typeof param) { case 'number': - return true; + return isFinite(param); case 'string': - return !isNaN(param); + return !(isNaN(param) || param == "null"); default: return false; } diff --git a/test/unit/core/error_helpers.js b/test/unit/core/error_helpers.js index e7a69eb6a2..ff2b870501 100644 --- a/test/unit/core/error_helpers.js +++ b/test/unit/core/error_helpers.js @@ -177,6 +177,28 @@ suite('Error Helpers', function() { 'ValidationError type is correct' ); }); + + testUnMinified('line: null string given', function() { + let err = assert.throws(function() { + p5._validateParameters('line', [1, 2, 4, "null"]); + }, p5.ValidationError); + assert.strictEqual( + err.type, + 'WRONG_TYPE', + 'ValidationError type is correct' + ); + }); + + testUnMinified('line: infinite value given', function() { + let err = assert.throws(function() { + p5._validateParameters('line', [1, 2, 4, Infinity]); + }, p5.ValidationError); + assert.strictEqual( + err.type, + 'WRONG_TYPE', + 'ValidationError type is correct' + ); + }); }); suite('validateParameters: trailing undefined arguments', function() {