tracker issue : CF-4198371

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

Unescaped query.column as struct key name yields unexpected results

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/AsDesigned

Reporter/Name(from Bugbase): Mosh Teitelbaum / Mosh Teitelbaum ()

Created: 02/28/2017

Components: Language

Versions: 2016

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: 2016.0.03.300466 /

Priority/Frequency: Normal / All users will encounter

Locale/System: ALL / Windows 10 64 bit

Vote Count: 0

Problem Description:

When creating a struct key and trying to use the value from a query as the key, not escaping the queryname.columnname returns an unexpected result. Instead of the value of the query column, it sets a nested struct as the key value.

Steps to Reproduce:
{code}
<cfset qry = queryNew("name,age", "varchar,Integer", [
{"name" : "Bob", "age" : 25}
]) />
<!--- This produces odd results --->
 <cfset str1 =
{ qry.age : qry.name }
/>
<cfdump var="#str1#" />
<!--- This produces expected results --->
 <cfset str2 =
{ "#qry.age#" : qry.name }
/>
<cfdump var="#str2#" />
{code}
 

Actual Result:

See screenshot for results.

Expected Result:

Both methods should produce a a struct with a key whose name comes from the query column.

Any Workarounds:

Escape the query.column reference.

Attachments:

  1. February 28, 2017 00:00:00: cf_error.png

Comments:

If we fix this bug then it will introduce an ambiguity in the grammar.for e.g {code:java} <cfscript> coInfo=StructNew(); coInfo.name="Adobe Systems Incorporated"; </cfscript> {code} here we are defining *name* as the key for struct colInfo, while initializing the value whereas its other interpretation can be that colInfo.Name has a value. To make the grammar unambiguous we are sticking to the convention that if you actually want to get a value in the key attribute of the struct its better to use # as the characters to get the value, rather than trying to imply it at run-time whether its a key definition for the new struct or a value needs to be supplied at the key.   Consider this example: {code:java} <cfset str1 = { qry.age : qry.name, qry.addr: "xyz"} /> <cfdump var="#str1#" /> {code} This becomes a perfectly feasible case where-in you want to define a new column *addr* to qry struct, Now how does compiler identify whether its a new column definition or whether you want to actually use the addr attribute value. To reduce these type of ambiguities the best thing to do is when you are defining a struct and you actually want to get the value of an attribute use *#*
Comment by Poonam Jain
29708 | September 17, 2018 10:50:59 AM GMT
Hi Poonam. I see your point but I'm not sure I agree that it is applicable in this specific scenario. Certainly, if you're using standard dot notation on the left side of an EQUAL SIGN, then the compiler should be able to assume that you are trying to create a new column/key, e.g.,: <cfset qry.newColumn = "foo" /> But when you're using the COLON NOTATION I think it can be safely assumed that you're not trying to define a new column/key, e.g.,: <cfset str = { qry.key : qry.value } />
Comment by Mosh Teitelbaum
29710 | September 17, 2018 03:08:10 PM GMT
Hi Mosh. We can column notation in this way as well. <cfset str2 = { "#qry.num#" : qry.age } /> and  <cfset str1 = { qry.num : qry.age} />   In first one we are using the value of num while in second we are defining a column name as age.It is not about assignment but using the value for defining new column/key.I hope I am able to clear my views here.   Thanks Poonam
Comment by Poonam Jain
29714 | September 18, 2018 06:58:58 AM GMT
Hi Poonam: I guess I can see it both ways. There are pros and cons to going either way. I guess instead of this being a bug, it's a feature that I was unaware of :) Thanks for your time.
Comment by Mosh Teitelbaum
29720 | September 18, 2018 06:38:36 PM GMT
Thanks Mosh! I am closing this bug now.  
Comment by Poonam Jain
29723 | September 19, 2018 09:43:14 AM GMT