tracker issue : CF-4207690

select a category, or use search below
(searches all categories and all time range)
Title:

ArraySort() callback chokes on large numbers returned

| View in Tracker

Status/Resolution/Reason: To Fix//BugVerified

Reporter/Name(from Bugbase): Bradley W. / ()

Created: 03/26/2020

Components: Language

Versions: 2016,2018

Failure Type: Crash

Found In Build/Fixed In Build: Final /

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Platforms All

Vote Count: 0

Consider this code (taken from Ben Nadel's blog).  Technically the docs require the callback to return -1, 0 or 1 but it's widely practiced to return any positive or negative number.  This code returns a number that cannot be cast to an integer type and it errors.  It would be nice for this to work.

{code}
<cfscript>
	// In our API responses, we return Date/Time stamps as UTC Milliseconds so that the
	// client-side code can simply do "new Date( utcMilliseconds )" and create a Date
	// object in the user's local timezone.
	projects = [
		{
			id: 1,
			name: "Really old project",
			createdAt: createDate( 2015, 12, 15 ).getTime() // 1450155600000
		},
		{
			id: 500,
			name: "Recent project",
			createdAt: createDate( 2019, 10, 30 ).getTime() // 1572408000000
		},
		{
			id: 1000,
			name: "Current project",
			createdAt: createDate( 2020, 02, 26 ).getTime() // 1582693200000
		}
	];
	projects.sort(
		( a, b ) => {
			// Sort the projects by CREATED DATE DESC (with most recent dates at the
			// top of the resultant array).
			// --
			// Ex: a: 2020, b: 2015
			// Result: ( (b)2015 - (a)2020 ) => -5 => (a) is sorted first.
			return( b.createdAt - a.createdAt );
		}
	);
	dump( projects );
</cfscript>
{code}

https://www.bennadel.com/blog/3795-array-sort-operator-must-return-int-sized-result-in-lucee-cfml-5-3-4-80.htm

Attachments:

Comments:

Oops, I was testing this on Lucee as well and left in the dump() function. That will need changed to writeDump() for Adobe CF. Related Lucee ticket: https://luceeserver.atlassian.net/browse/LDEV-2793
Comment by Bradley W.
33314 | March 26, 2020 05:33:12 PM GMT