tracker issue : CF-4204982

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

Struct key uppercase/lowercase inconsistency

| View in Tracker

Status/Resolution/Reason: To Track//CannotReproduce

Reporter/Name(from Bugbase): Timo T. / ()

Created: 08/08/2019

Components: AJAX

Versions: 2018

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: Adobe ColdFusion (2018 Release) Update 3 installed /

Priority/Frequency: Normal / Few users will encounter

Locale/System: English / Win 2016

Vote Count: 1

Problem Description: 

When doing an AJAX call to a CF file from Javascript, the struct keys in the returned data sometimes show up in uppercase when doing a console.dir() in the Javascript code. preserveCaseForStructKey setting has been added to Application.cfc but it does not seem to work, or only works intermittently. 

In our case the application is built on top of ColdBox, but having seen others have a similar issue (e.g. https://forums.adobe.com/thread/1095066 , https://forums.adobe.com/thread/1533551, https://forums.adobe.com/thread/1527265, https://stackoverflow.com/questions/12217698/preserving-case-for-coldfusion-structs-when-converted-to-json) I think it's not ColdBox-related. Mainly I'm wondering why the preserveCaseForStructKey setting seems to have effect only sporadically.


Steps to Reproduce:

Reproducing this issue is difficult since it does not happen every time, and I've been unable to pinpoint a real consistency behind the issue popping up or going away: 
-Sometimes the restart of the Coldfusion server, clearing the template/component caches or reinitializing the application with fwreinit causes the subsequent AJAX calls to have their struct keys converted to uppercase
-Similarly, sometimes a restart, cache clear or fwreinit makes the issue go away (only to appear again later)

There most likely is some more specific logic to this behavior, but I'm afraid I've not spotted it.

A barebones example of an application where we've encountered this:

1. Add the following line to Application.cfc:
<cfset this.serialization.preserveCaseForStructKey = true />

2. Create a Coldbox handler file with the following function:

public void function testFunction() {

	var test_structs = [
		{
			foo: "foovalue",
			bar: {
				baz: "bazvalue"
			}
		},
		{
			foo2: "foovalue2",
			bar2: {
				baz2: "bazvalue2"
			}
		}];

	event.renderData(type="JSON", data=test_structs);

}

3. Call the handler from Javascript with e.g.:

$.ajax({
	url: "/path/to/index.cfm?event=module:handler.testFunction",
	type: "post",
	dataType: "json",
	success: function(data) {
		console.dir(data);
	}
});


Actual Result: 

Occasionally the console.dir() will show struct keys incorrectly as FOO, BAR, BAZ and so on. Other times, they are foo, bar, baz etc. as expected.


Expected Result:

The keys are in lowercase every time.


Any Workarounds: 

Declaring the struct with quoted keys, e.g. 

var test_struct = [
	{
		"foo": "foovalue",
		"bar": {
			"baz": "bazvalue"
		}
	},
	{
		"foo2": "foovalue2",
		"bar2": {
			"baz2": "bazvalue2"
		}
	}];

...but we have not had that syntax in place long enough to be able to tell if it fixes the issue for good, or if the uppercase conversion will still happen again at some point.

Attachments:

Comments: