Skip to content
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

ToNumber incorrectly accepts "INFINITY" #885

Closed
gibson042 opened this issue Mar 24, 2022 · 1 comment
Closed

ToNumber incorrectly accepts "INFINITY" #885

gibson042 opened this issue Mar 24, 2022 · 1 comment
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.

Comments

@gibson042
Copy link

Environment: XS 11.6.0 32 4

Description
XS incorrectly converts a string like "INFINITY" into Infinity rather than NaN.

Steps to Reproduce

const inputs = ["Infinity", "INFINITY", "infinity", "inFiNiTY"];
inputs.map(str => `Number("${str}") // => ${Number(str)}`).join("\n");
// =>
// Number("Infinity") // => Infinity
// Number("INFINITY") // => Infinity
// Number("infinity") // => NaN
// Number("inFiNiTY") // => NaN

Expected behavior
Only the "Infinity" capitalization should be given special treatment, with all other variants converted to NaN per StringToNumber parsing input against StringNumericLiteral.

Actual behavior
XS privileges both "Infinity" and "INFINITY".

@phoddie
Copy link
Collaborator

phoddie commented Mar 24, 2022

The bug appears to happen because the match function used by dtoa2 is case insensitive.

The only other place match is used is to detect NaN. But there's no problem there because "NAN" evaluates to NaN anyway.

So, it looks like it would be enough to modify match to be case-sensitive.

@phoddie phoddie added the confirmed issue reported has been reproduced label Mar 24, 2022
mkellner pushed a commit that referenced this issue Mar 30, 2022
@phoddie phoddie added the fixed - please verify Issue has been fixed. Please verify and close. label Mar 30, 2022
@phoddie phoddie closed this as completed May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.
Projects
None yet
Development

No branches or pull requests

2 participants