Skip to content

NaN and infinity check for isNumber #5846

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

oscarczer
Copy link

Resolves #5675

Changes:

Implemented an additional checker for null strings and infinite values in isNumber within validate_params.js

Screenshots of the change:

Screen Shot 2022-10-25 at 11 28 20 pm

PR Checklist

@welcome
Copy link

welcome bot commented Oct 25, 2022

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@@ -344,9 +344,9 @@ if (typeof IS_MINIFIED !== 'undefined') {
const isNumber = param => {
switch (typeof param) {
case 'number':
return true;
return isFinite(param);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think finite number check should be implemented here as mentioned in the original issue there could still be utility for using Infinity in certain circumstances and if drawing functions are ever to enforce finite only numbers they should be done in the drawing functions themselves instead of in the general case here.

case 'string':
return !isNaN(param);
return !(isNaN(param) || param == "null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another special case that needs to be accounted for here which is when param === "" or param === " " for any number of spaces in the string. Accounting for this can potentially add some complexity, alternatively we can attempt to do parseFloat(param) first to directly test if the result is NaN which also have the benefit of possibly not needing to use different switch cases here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: include an error message when drawing shapes with NaN values.
3 participants