Copy link to clipboard
Copied
My CF2023 site has been running perfectly until now when suddenly I'm getting errors related to argument names containing hyphens. I'm assuming it's the hyphen that's the problem.
The name FILE-0 used for an argument has illegal characters in it.
The site is hosted and I'm asking the admins if they've made any changes. They can be slow to respond, so in the meantime I'm just wondering if anyone has a clue.
I'm thinking it may be reading the hyphen as a minus sign. But why suddenly?
These fields are dynamically appended to the sending form depending on how many files are uploaded by the user. So there could be up to 20 arguments from "FILE-0" to "FILE-20" being passed to the cfc as arguments.
The form is submitted like the following:
<cfset stRes = oListing.saveListing(argumentCollection=form,json=true)>
And it just sends whatever the form contains.
Any insight appreciated.
Copy link to clipboard
Copied
That doesn't surprise me. With every new ColdFusion version and update, Adobe's engineers make the language more accurate and less tolerant of ambiguities and mistakes.
You will agree that the following code is ambiguous:
<cfset myVar-i==3>
Naming a variable file-3 is doubly problematic. Not only does it use the hyphen, which is already a problem. It also uses "file" which, in some circumstances, is a struct that represents the properties of a file.
That said, you might be able to use the name file-3 in bracketed notation. For example,
form["file-3"]
However, as the documentation suggests, the ultimate test of a valid variable name is whether or not it would work in Java. If I were you, I would change names such as "file-X" to "file_X". If only for peace of mind.
Copy link to clipboard
Copied
OK, just spent ages changing the many instances of hyphens to underscores, and it solved those problems.
Came across a potentially tricky one though:
A file upload form has the following code:
<input type="file" name="files[]" multiple>
However, as you probably guessed already, the cfc errors:
Function init does not support FILES[] as an argument.
The name files[] used for an argument has illegal characters in it.
The illegal chars are, of course, the square brackets. I may be searching for new file uploader shortly.
Copy link to clipboard
Copied
I do remember the name files[] from your thread about file upload. 🙂
Copy link to clipboard
Copied
Yeah, it took me half of forever to sort that out and now I can't use it, lol
Copy link to clipboard
Copied
That's to be expected in software development, I suppose. In any case, this cloud has a silver lining. In fixing things now, you're future-proofing the software, making life easier for a future colleague or for your future self.
Copy link to clipboard
Copied
Are you satisfied with the shared insights? Is your question answered?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now