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

Can anyone explain what is happening in this example?

Guest
May 24, 2013 May 24, 2013

Copy link to clipboard

Copied

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.

Views

559

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
Engaged ,
May 28, 2013 May 28, 2013

Copy link to clipboard

Copied

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.

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
LEGEND ,
May 28, 2013 May 28, 2013

Copy link to clipboard

Copied

LATEST

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.

--

Adam

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