Scipting version "switch / case" does not work with the comma as standard delimiter

It seems, that the scipting version “switch / case” does not work with the comma as standard delimiter?!
Can anyone pleas test this code snippet?

<cfset variables.exp = "demo">
<cfswitch expression="#variables.exp#">
  <cfcase value="test,demo">
    Tag based output -> test,demo
  </cfcase>
  <cfdefaultcase>
    Tag based output -> Default value
  </cfdefaultcase>
</cfswitch>

<br>
<br>

<cfscript>
    exp = "demo";
    switch("#exp#"){
        case "test,demo":
            writeOutput("Script based output -> test,demo");
            break;
        default:
            writeOutput("Script based output -> Default value");
    }
</cfscript>

My enviroment:
OS: Debian 9.13 - Linux
Java Version: openJDK-11.0.11
Tomcat Version: 9.0.48
Lucee Version: Lucee 5.3.8.201

This would be done using separate case statements:

<cfscript>
    exp = "demo";
    switch("#exp#"){
        case "test":
        case "demo":
            writeOutput("Script based output -> test,demo");
            break;
        default:
            writeOutput("Script based output -> Default value");
    }
</cfscript>

Take a look at cfswitch Code Examples and CFML Documentation for more details.

1 Like

Hi Martin,

thank you for clarifying and the very helpfull link.

i added a note to the Lucee docs about this ‘quirk’

Thank you. I think it would be more clear, when it’s also reflected in the doc’s code example, that you can use the syntax:

...
case "any-1":  case "any-2":
    result = "the result";
    break;
...

PRs are always welcome!

I’ve created 2 PRs.