Details
Assignee
Michael OffnerMichael OffnerReporter
Dan Switzer, IIDan Switzer, IILabels
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
Priority
New
Details
Details
Assignee
Michael Offner
Michael OffnerReporter
Dan Switzer, II
Dan Switzer, IILabels
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
Priority
Created 14 September 2020 at 17:43
Updated 23 July 2022 at 10:11
Lucee does not process switch statements the same way ACF does in regards to the "default" statement. Take the following code:
function switchTest(required numeric input){ switch(arguments.input){ case 1: return "item 1"; case 2: default: return "item 2"; case 3: return "item 3"; case 4: return "item 4"; } } writeOutput("<div>1 = #switchTest(1)#</div>"); writeOutput("<div>2 = #switchTest(2)#</div>"); writeOutput("<div>3 = #switchTest(3)#</div>"); writeOutput("<div>4 = #switchTest(4)#</div>"); writeOutput("<div>-1 = #switchTest(-1)#</div>");
If you run this under ACF, you get the following results:
1 = item 1 2 = item 2 3 = item 3 4 = item 4 -1 = item 2
Which is what I'd expect.
However, Lucee 4.2 - Lucee 5.3 this produces:
1 = item 1 2 = item 3 3 = item 3 4 = item 4 -1 = item 2
The value for
2
ends up showingitem 3
where I'd expect it to showitem 2
.This works properly if you move the
case 2:
/default:
block to the end of the switch statement:Here's a Gist which illustrates the bug:
https://www.trycf.com/gist/ab87d523b5c7ee657c3ba39e5225e5e7/acf11?theme=monokai