Skip to main content
Inspiring
May 22, 2025
Question

Hyphens in argument names

  • May 22, 2025
  • 1 reply
  • 674 views

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.

 

    1 reply

    BKBK
    Community Expert
    Community Expert
    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. 

    paul_8809Author
    Inspiring
    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.

     

    BKBK
    Community Expert
    Community Expert
    May 23, 2025

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