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

& is not encoding correctly in ColdFusion

Explorer ,
May 08, 2013 May 08, 2013

Copy link to clipboard

Copied

I am using "&amp" in a coldfusion variable and assigning this to another variable. And I dumped this variable but am not getting results as I expected instead it outputting as below.

<cfset x = "abdul & latheef">

<cfset y = x>

<cfdump var = "#x#">

<cfdump var = "#y#">

Actual Output:

x = abdul &amp latheef

y = abdul &amp latheef

Expected Output:

x = abdul & latheef

y = abdul & latheef

Any idea about this why am getting output as I explained in Actual Output: . Timely help well appreciated.

Views

862

Translate

Translate

Report

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
Advocate ,
May 08, 2013 May 08, 2013

Copy link to clipboard

Copied

Why would you expect an ampersand instead of the HTML encoding?  You are dumping the value of the variable, which contains the encoded version.  Just as if you outputted the variable.

If you output that variable to the browser you will also get the encoded version, but *the browser* will properly decode it to the ampersand. That is the result you *should* be desiring.

Jason

Votes

Translate

Translate

Report

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
Explorer ,
May 15, 2013 May 15, 2013

Copy link to clipboard

Copied

Thanks for the replay.

So you meant to say if we are output that variable into the browser which will allways give the encoded version(that is "&amp"). Please correct me if I am wrong or I understood in different way.

Here I am getting different results in different environments that is , I am getting "&amp" in one browser in QA environment and just "&" in same browser(IE) but in development environment.

Votes

Translate

Translate

Report

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 17, 2013 May 17, 2013

Copy link to clipboard

Copied

LATEST

& is correctly encoded in ColdFusion. The result you're getting is expected.

Now, some explanations. Browsers do in general render & as &. You should realize that the cfdump tag converts & into &, whereas cfoutput leaves it intact. Hence, if you run this code, 

<cfset x = "abdul & latheef">

<cfoutput>#x#</cfoutput><br>

<cfdump var = "#x#">

the result sent to the browser will effectively be

abdul & latheef<br>

abdul & latheef

The browser renders this as

abdul & latheef

abdul & latheef

which is the final result you see. However, if your starting point is this code instead

<cfset x = "abdul & latheef">

<cfoutput>#x#</cfoutput><br>

<cfdump var = "#x#">

then the result sent to the browser will effectively be

abdul & latheef<br>

abdul &amp; latheef

The browser renders this as

abdul & latheef

abdul & latheef

This explains why you see abdul & latheef.

Votes

Translate

Translate

Report

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
Documentation