From f0a40966949c7677b2b0b41e413a1cbf9a27d9ec Mon Sep 17 00:00:00 2001 From: CF Mitrah Date: Fri, 8 May 2026 18:45:03 +0530 Subject: [PATCH] Implemented fixes for LDEV-6302 and added test cases for the StructToSorted() function. --- .../functions/struct/StructToSorted.java | 2 +- test/tickets/LDEV6302.cfc | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/tickets/LDEV6302.cfc diff --git a/core/src/main/java/lucee/runtime/functions/struct/StructToSorted.java b/core/src/main/java/lucee/runtime/functions/struct/StructToSorted.java index 2e367538734..6a6f8b0103c 100644 --- a/core/src/main/java/lucee/runtime/functions/struct/StructToSorted.java +++ b/core/src/main/java/lucee/runtime/functions/struct/StructToSorted.java @@ -34,7 +34,7 @@ public static Struct call(PageContext pc, Struct base) throws PageException { } public static Struct call(PageContext pc, Struct base, Object sortTypeOrSortFunc) throws PageException { - if(Decision.isSimpleValue(sortTypeOrSortFunc)) call(pc, base, Caster.toString(sortTypeOrSortFunc), "asc", false); + if(Decision.isSimpleValue(sortTypeOrSortFunc)) return call(pc, base, Caster.toString(sortTypeOrSortFunc), "asc", false); return _call(pc, base, Caster.toFunction(sortTypeOrSortFunc)); } diff --git a/test/tickets/LDEV6302.cfc b/test/tickets/LDEV6302.cfc new file mode 100644 index 00000000000..147195b2241 --- /dev/null +++ b/test/tickets/LDEV6302.cfc @@ -0,0 +1,49 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" label="LDEV-6302"{ + + function beforeAll() { + + // Struct with mixed-case keys for text and textNoCase tests + variables.textStruct = { + Zulu: { label: "Zulu" }, + alpha: { label: "Alpha" }, + MIKE: { label: "Mike" } + }; + + // Struct for numeric test + variables.numericStruct = { + "10": "ten", + "2": "two", + "1": "one" + }; + + } + + function run( testResults, testBox ) { + describe( title="LDEV-6302: struct.toSorted/StructToSorted single-argument string defaults sortOrder to asc", body=function() { + it( title="member toSorted('text') with one argument defaults to ascending order", body=function( currentSpec ) { + expect( + structKeyList(duplicate(variables.textStruct).toSorted("text"), ",") + ).toBe("alpha,MIKE,Zulu"); + } ); + + it( title="member toSorted('textNoCase') with one argument defaults to ascending order", body=function( currentSpec ) { + expect( + structKeyList(duplicate(variables.textStruct).toSorted("textNoCase"), ",") + ).toBe("alpha,MIKE,Zulu"); + } ); + + it( title="member toSorted('numeric') with one argument defaults to ascending order", body=function( currentSpec ) { + expect( + structKeyList(duplicate(variables.numericStruct).toSorted("numeric"), ",") + ).toBe("1,2,10"); + } ); + + it( title="StructToSorted(base,'text') with one argument defaults to ascending order", body=function( currentSpec ) { + expect( + structKeyList(StructToSorted(duplicate(variables.textStruct), "text"), ",") + ).toBe("alpha,MIKE,Zulu"); + } ); + } ); + } + +}