Question

Is it possible to preserve the case of the GET field names in ColdFusion MX 7 (the case is preserved in CF9)? I've searched tirelessly for an answer but all solutions seem to be POST specific, whereas this is a GET.

N.B. I am aware that RFC2616 states that HTTP field names are case-insensitive, but we're all aware how easy specifications can be deviated from...

EXAMPLE:

Given the following ColdFusion script (let's call it 'url-case-test.cfm'):

<html>
    <body>
        <cfoutput>
            #structKeyList(url)#
        </cfoutput>
    </body>
</html>

And navigating to this script using the following parameter decorated URL:

http://localhost:8080/cfusion/url-case-test.cfm?name1=value1&name2=value2&name3=value3

I get the output:

NAME1,NAME2,NAME3

Any suggestions on how I preserve the case? Help would be greatly appreciated.

Was it helpful?

Solution

Another option is using getParameterMap() which returns a case-sensitive structure of parameters.

<cfset map = getPageContext().getRequest().getParameterMap()>
<cfoutput>#structKeyList(map)#</cfoutput>

OTHER TIPS

I think the only thing you're going to be able to do is parse the CGI.QUERY_STRING value.

<cfset paramList="" />
<cfloop list="#CGI.QUERY_STRING#" index="qsparam" delimiters="&">
  <cfset paramList=listAppend(paramList,listFirst(qsparam,"=")) />
</cfloop>
<cfoutput>#paramList#</cfoutput>

Don't store the URL parameters in a structure as keys, though, or you'll lose your case all over again.

This is obviously not ideal, as any URL values you've set via cfparam or cfset (or any other way manipulations of the URL object) will get lost.

Which version of CF are you using? In ACF9 and Railo 3.3 case is definitely preserved.

I've a bit changed your sample URL for testing purposes:

?nAmE1=ValuE1&name2=value2&name3=value3

Code:

<cfdump var="#url#" />

<cfloop collection="#url#" item="key">
    <cfoutput>#key#<br/></cfoutput>
</cfloop>

<cfoutput>#structKeyList(url)#</cfoutput>

ACF9:

enter image description here

Railo:

enter image description here

As per my knowledge it is not possible. Coldfusion always Capitalize structure key name. If have limited list of URL keys then just create comma separated new key list and pass as separate URL key. This is what I had use before.

If you want to maintain case you would just use array notation to build the struct within your loop.

<cfset paramStruct = StructNew()>
<cfloop list = "#CGI.QUERY_STRING#" index="i" delimiters="&">
  <cfset paramStruct[ listFirst(i,"=") ] = listLast(i,"=")>
</cfloop>

<cfdump var="#paramStruct#">

I have not tested this but I assume it will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top