Skip navigation
Currently Being Moderated

Can anyone explain what is happening in this example?

May 24, 2013 2:44 PM

Tags: #cf9 #cfsavecontent #utf-16

Take a look at the following bit of CFML:


<!---\\ This is a coldfusion comment \\--->
<cfif false>
          <cfsavecontent variable="Test">
                    <?xml version="1.0" encoding="utf-16"?>

<!---\\ Some other coldfusion code \\--->
<cfset Foo = 'Hello '>
<cfset Bar = 'World'>
<cfset FooBar = Foo & Bar>


Seems like some simple test code right? Shouldn't generate any output at all right? Now take that sample and go run it. Are you staring at a jumble of oddly encoded characters that basically contain all of the unprocessed CFML code on the page? Because that's exactly what I'm looking at.


It's the craziest thing! The root issue is the "utf-16" attribute of the XML declaration. If you remove that or change it to something like "utf-8", everything is fine. The points that really muddle my brain are:

  1. The XML declaration is inside a "cfsavecontent" tag so it should just be a string
  2. The "cfsavecontent" should not even be evaluated because it's inside of a "cfif" that's hard-coded to false


My coworker came across this while trying to save some XML as a string so he could write it to a file later. It really seems like a crazy bug to me but I'd like to hear what others think is going on here. For your info, we're running CF9 standard on a Win2k8 R2 system.

  • Currently Being Moderated
    May 28, 2013 3:01 AM   in reply to AmericanWebDesign

    Seems fine for me, using CF 9 Enterprise on Windows 7.  You may want to try setting the encoding part of the string to a variable.  Or prepending that to the XML string afterwards, something like that.

    Mark as:
  • Currently Being Moderated
    May 28, 2013 3:10 AM   in reply to duncancumming

    The only thing I can think is that the file itself is saved with UTF-16 encoding, and the CF compiler is baulking at that. That said, I emulated this on my PC and my CF install (same as Duncan's, we work in the same office) dealt with it just fine.


    If the file is saved in any sort of non-ANSI encoding, you will need a <cfprocessingdirective> at the top of the file to tell the CF compiler how to read the file.




    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points