Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hyphens in argument names

Participant ,
May 22, 2025 May 22, 2025

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.

 

374
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 22, 2025 May 22, 2025

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 22, 2025 May 22, 2025

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2025 May 23, 2025

I do remember the name files[] from your thread about file upload. 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 23, 2025 May 23, 2025

Yeah, it took me half of forever to sort that out and now I can't use it, lol

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2025 May 23, 2025

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.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2025 May 26, 2025
LATEST

Are you satisfied with the shared insights? Is your question answered?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources