IsNumeric returns True on strings like "3d" and "6f" (5.3.8 regression!)

Description

The change done for tickets https://luceeserver.atlassian.net/browse/LDEV-2747#icft=LDEV-2747 and LDEV-2353, which is already deployed as a RC in 5.3.8.47, introduces a new bug for `isNumeric()`.

When the string to test ends with a “d” or an “f” (a java type qualifier for Double / Float), `isNumeric()` will now return true.

Before this change, it returned False (tested with trycf.com on 5.3.7 and 4.5, and ACF 2021)

Code to test:

<cfoutput> <cfset tests = ['35e3f', '6f', '6.6f', '2d', '3.3d', '6.62607004e-34', '12E4d', '123456789L', '123456789l']> <cfloop array="#tests#" index="i"> isNumeric('#i#') = #isNumeric(i)#<br> </cfloop> </cfoutput>

Output on Lucee 5.3.8.139-RC:

isNumeric('35e3f') = true isNumeric('6f') = true isNumeric('6.6f') = true isNumeric('2d') = true isNumeric('3.3d') = true isNumeric('6.62607004e-34') = true isNumeric('12E4d') = true isNumeric('123456789L') = false isNumeric('123456789l') = false

Environment

all

Activity

Pothys - MitrahSoft 8 March 2021 at 09:55

I've checked this ticket with fixed versions and this issue was fixed. So I close this ticket.

Paul Klinkenberg 5 March 2021 at 18:38

Awesome @Michael Offner ! Everything looks good now, as far as I can read the code on my mobile.

And p.s.: Hi buddy👋 Long time no see 😁

Michael Offner 5 March 2021 at 18:15

I extended the existing isNumber function and removed the addional independent check, i also added all test cases.

https://github.com/lucee/Lucee/commit/d6f297d7d327852d6c4df8e74e0c6f8db8e996c3

Paul Klinkenberg 16 February 2021 at 16:25

I was checking this commit, and with that, the actual implementation. I see there are 2 different isNumeric() implementations, which both try to do the same, but in a completely different manner:

Worse even, the implementation isNumber(String str) still does not allow for a negative exponent, like 3e-5, if I read the code correctly.

My suggestion would be, to start using just one of the 2 implementations, and remove the other one.

If using the string parser, you could add a few tests for the things tested in this function, eg.

expect(isNumeric('+123')).toBe(true); expect(isNumeric('-123')).toBe(true); expect(isNumeric('+12+3')).toBe(false); expect(isNumeric('-12-3')).toBe(false); expect(isNumeric('12+3')).toBe(false); expect(isNumeric('12-3')).toBe(false); expect(isNumeric('+')).toBe(false); expect(isNumeric('-')).toBe(false);

Pothys - MitrahSoft 16 February 2021 at 14:58

I added a fix and testcase for this ticket.

Pull request: https://github.com/lucee/Lucee/pull/1193

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Affects versions

Created 10 February 2021 at 09:07
Updated 29 July 2023 at 07:01
Resolved 8 March 2021 at 09:56