tracker issue : CF-4198801

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

Quoted variable assignment errors when using keys that start with a number

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): Thomas Harding / Thomas Harding ()

Created: 05/30/2017

Components: Language

Versions: 2016

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: Latest / 2020.0.0.314573

Priority/Frequency: Normal / All users will encounter

Locale/System: English / Windows 10 64 bit

Vote Count: 1

Problem Description: When fully quoting variable name assignment using dynamic keys, coldfusion errors when attempting to use a key that STARTS with a number. eg, "12345User" throws, but "User12345" does not.

Steps to Reproduce: The following code demonstrates the issue:

variables.key1 = "abc";
"variables.#variables.key1#" = "key1 works";

variables.key2 = "123";
variables[ variables.key2 ] = "key2 works!";

variables.key3 = "abc123";
"variables.#variables.key3#" = "key3 works!";

variables.key4 = "123";
"variables.#variables.key4#" = "key4 works!";

variables.key5 = "123abc";
"variables.#variables.key5#" = "key5 works!";

writeDump( var=variables );

Actual Result:

"Error: The string VARIABLES.variables.123 is not a valid ColdFusion variable name"

Expected Result:

All 5 keys should work using this notation.

Any Workarounds:

Use square bracket notation. However, this is not necessarily practical, as some javascript libraries that we use are sending the data in the format 'data[123][abc] = "this is some data"', where most other languages will automatically translate this to a struct, I have been using the quoted string notation as above to translate to struct data. Given that the depth of structs/keys could vary, it's far simpler to have it assigned this way, without needing to manually parse the keys and build up the resulting data struct in cf.



TBH I think the current behaviour is legit. It's documented what variable names are valid with dot notation (starts with letter, underscore; contains only those two and digits and currency symbols). if you have runtime/unknown/"invalid" values, you should use associative array notation which is what it's there for. I reckon there's perhaps a case for an *enhancement request* to alter the rules of what constitutes a valid dot-notation variable reference, but I can't see how this is a "bug".
Comment by Adam C.
636 | May 31, 2017 10:58:52 AM GMT
@Adam - perhaps fair shout on it being documented as inavalid, so maybe not best described as a bug. However, I've just tested the following on my local CF2016 and CF11 installs: variables.123 = "this works"; writeDump( var=variables, abort=true ); I double checked the docs after reading your comment, and apparently this should be invalid? So either the docs are wrong, or coldfusion is being inconsistent? If I can manually set a variable with a numeric key, counter to what docs suggest, then surely logically I should be able to set the key dynamically as per the original ticket. I'm happy to amend the ticket if people think I'm clearly wrong.
Comment by Thomas H.
637 | May 31, 2017 01:57:38 PM GMT