Arguments with type of "numeric" are not being cast to double

Description

Functions that have arguments specified as "numeric" do not treat the values as numeric.

For example, take the following function:

function isPositive(required numeric input, boolean debug=false) output=true { return (abs(arguments.input)== arguments.input); }

Now if you run the following, the results may not be as expected:

isPositive(0.08263888888888889); // returns true isPositive("0.08263888888888889"); // returns false

In ACF, both would return true, and that's what I'd expect to happen here.

The problem is that arguments.input ends up equaling 0.08263888888888889 when the original input is a string, but when run through abs() it ends up being cast to a double and becomes 0.082638888889 so when the values are compared, they are not equal.

Here is a gist that shows off the issue:
https://www.trycf.com/gist/14bea07bc4311e74b5c06cc93b1280ad/lucee5?theme=monokai

It would seem like values being passed into a function with a data type of numeric should be cast to a double so that all math operations match. However, that could have some real ramifications.

Alternatively, perhaps the comparison functions just need to be fixed so that when comparing a value that's a "string" to a native number type, that the string is cast to the same number type (i.e. cast to a double) so that the strings would be compared equally.

Environment

Tomcat 9/CentOS 7/Apache 2.4

Attachments

1
  • 01 Jun 2023, 06:12 am

Activity

Show:

Pothys - MitrahSoft 1 June 2023 at 06:12
Edited

I checked this ticket with lucee version 6.0.0.419-SNAPSHOT. Now arguments with type "numeric" are converted to double and the issue is solved. But still issue not get fixed on lucee 5.3

Zac Spitzer 31 May 2023 at 11:29

Just tried this with Lucee 6 and the disabled test cases passed ( I merged them together )

https://github.com/lucee/Lucee/commit/4c3243b368d4e733a9052645356192c39d4fd8c4

Zac Spitzer 28 April 2022 at 02:54

Lucee only checks if the argument is castable to the type, it doesn’t cast arguments

Pothys - MitrahSoft 11 September 2020 at 07:45

I've checked this ticket and confirmed the issue happened on lucee. Works fine with ACF. I added a test case for this issue.

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

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 September 2020 at 14:01
Updated 9 June 2023 at 15:32
Resolved 9 June 2023 at 15:32

Flag notifications