Lucee "switch" statement corrupts output when "default" case not last


Lucee does not process switch statements the same way ACF does in regards to the "default" statement. Take the following code:

If you run this under ACF, you get the following results:

Which is what I'd expect.

However, Lucee 4.2 - Lucee 5.3 this produces:

The value for 2 ends up showing item 3 where I'd expect it to show item 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:


Dan Switzer, II
September 14, 2020, 5:52 PM

It’s probably worth adding that I’m not aware of any spec that requires the {{default}} statement to be the last statement. ECMAScript does not require the statement to be last:

This produces the same output as ACF:

1 = item 1
2 = item 2
3 = item 3
4 = item 4
-1 = item 2

Pothys - MitrahSoft
September 15, 2020, 3:50 PM

I've checked this ticket and confirmed the issue happened on lucee latest version also. And added a test case for this ticket too.

Pull Request:


Michael Offner


Dan Switzer, II


Affects versions