cfswitch doesn't convert a boolean value to a numeric value

Description

The docs say:

*Any CFML expression that yields a scalar value. CFML converts integers, real numbers,
Booleans, and dates to numeric values.*

This sample returns "don't know", but should return "it's true"

```

<cfset test = true>

<cfswitch expression="#test#">
<cfcase value="1">
<cfoutput>it's true</cfoutput>
</cfcase>
<cfcase value="0">
<cfoutput>it's false</cfoutput>
</cfcase>
<cfdefaultcase>
<cfoutput>don't know</cfoutput>
</cfdefaultcase>
</cfswitch>
```

Environment

None

Activity

Show:

Pothys - MitrahSoft 9 January 2018 at 08:30

I've added test case this ticket & confirmed the issue happened on latest version of lucee also 5.2.6.29 snapshot. CFswitch case in tag based doesn't convert boolean to numeric value. Script based is working as expected.

Pull Request: https://github.com/lucee/Lucee/pull/367

Former user 2 September 2015 at 23:07

Can confirm that this is an issue in Lucee 4.5 and 5

<cffunction name="foo"> <cfargument name="test" type="boolean"> <cfswitch expression="#arguments.test#"> <cfcase value="1"> <cfoutput>it's true</cfoutput> </cfcase> <cfcase value="0"> <cfoutput>it's false</cfoutput> </cfcase> <cfcase value="true"> <cfoutput>it's literally true</cfoutput> </cfcase> <cfdefaultcase> <cfoutput>don't know</cfoutput> </cfdefaultcase> </cfswitch> </cffunction> <cfscript> foo( true ); switch(true){ case 1: writeOutput("Passed - true"); break; case 0: writeOutput("Passed - false"); break; default: writeOutput("Failed"); } </cfscript>

Will sort out some unit tests tomorrow

Imported User 87 11 March 2015 at 15:17

This is not a bug in cfscript:

Passes on all conditions. switch(true){ case 1: writeOutput("Passed - true"); break; case 0: writeOutput("Passed - false"); break; default: writeOutput("Failed"); }
Fixed

Details

Assignee

Reporter

Priority

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

Affects versions

Created 3 March 2015 at 15:53
Updated 21 May 2024 at 23:22
Resolved 21 May 2024 at 23:22

Flag notifications