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

Description

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:
https://www.trycf.com/gist/ab87d523b5c7ee657c3ba39e5225e5e7/acf11?theme=monokai

Activity

Show:
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 5.3.8.72-SNAPSHOT also. And added a test case for this ticket too.

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

Assignee

Michael Offner

Reporter

Dan Switzer, II

Labels

Affects versions

Priority

New
Configure