2 Replies Latest reply on May 28, 2013 3:10 AM by Adam Cameron.

    Can anyone explain what is happening in this example?

    AmericanWebDesign Level 1

      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"?>
                </cfsavecontent>
      </cfif>
      
      
      <!---\\ 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.