CFScript's writeDump Doesn't Always Work | cfdump -vs- writeDump - coldfusion

On ACF 10, I have a function with the following signature...
<cffunction name="...">
<cfargument ...>
<cfdump var="#arguments#" output="#expandPath('/files/logs/debug.txt')#">
<cfscript>
writeDump(var="#arguments#", output="#expandPath('/files/logs/debug.txt')#");
</cfscript>
</cffunction>
The first tag-based dump works, but the second script-based dump does not. I've had this problem before and I've definitely gotten the tag based dump to work before. It seems random. Sometimes it works, sometimes it doesn't. Once it starts working, it continues... but when it doesn't I can't figure out why.
On the script based variant, I've also tried...
WriteDump(...)
removing the comma separating the two attributes (an other working example is written this way oddly enough)
removing the trailing semi-colon which apparently isn't always necessary per this... Why writedump function doesn't require semicolon in cfscript?
Anyone else having this problem and or know what the solution could be?
PS. Anywhere there's a "..." above, it's just to note that that bit is unimportant

Related

cfif statement with no expression or conditionals

Took over some code and I found this logic:
<cfif FALSE>
execute this code
<cfelse>
execute this
</cfif>
There is no conditional or expresssion for the IF statement. Just hanging out there as 'FALSE'. What is this statement evaluating then? OR What is the default expression of a cfif statement?
That example will always run the "execute this" bit (the cfelse). The "execute this code" bit will never run. Looks like an odd way of preventing a chunk of old code from running. The "execute this code" bit could've just been commented-out or removed (and thus no need for the cfif/cfelse tags).

An invalid XML character (Unicode: 0x1e) in Coldfusion XML output

I am attempting to output a query to a simple XML document. I have used this same code multiple times for other queries and it worked fine. It seems there is a bad character in the description field somewhere and XMLformat() is not filtering it out. I have tried numerous REReplace() filters to no avail. Also tried Ben Nadel's technique found here. http://www.bennadel.com/blog/1155-Cleaning-High-Ascii-Values-For-Web-Safeness-In-ColdFusion.htm and everything has resulted in the same error. I did dump the output and search for bad characters and I found nothing. This simple thing has turned into quite the mystery. I am using the code below.
<cfquery name="list" datasource="theDatasource">
SELECT ItemID, ItemCode, BrandName, description
FROM theTable
</cfquery>
<cfxml variable="outputXML">
<itemsBrand>
<cfoutput query="list">
<itemBrand>
<ItemID>#XmlFormat(ItemID)#</ItemID>
<ItemCode>#XmlFormat(ItemCode)#</ItemCode>
<BrandName>#XmlFormat(BrandName)#</BrandName>
<description>#XmlFormat(description)#</description>
</itemBrand>
</cfoutput>
</itemsBrand>
</cfxml>
<cffile action="write" file="#GetDirectoryFromPath(GetCurrentTemplatePath())#itemBrand.xml" output="#toString(outputXML)#"/>
Is resulting in the error "An invalid XML character (Unicode: 0x1e) was found in the element content of the document." Any help would be appreciated.
It seems a bit odd it's barfing on a 0x1E, which is just a greater-than symbol. (edit: no it ain't; not sure why I came to that conclusion. AC).
It might be an idea to swap out the <cfxml> for <cfsavecontent> temporarily so you can build the string, then parse it to find out what's not right about it. That should give you more clue how to sort it out. But xmlFormat() is supposed to deal with wayward angle-brackets.
One other thing: if all you're doing with this XML is to then serialise it and write it to file, you don't actually need to use <cfxml> anyhow. Just continue to use <cfsavecontent> anyhow. If you want a string: just make a string.

Turn off auto indent in sublime text 2, but

Right now in sublime text 2 when I start an if statement in Coldfusion and hit enter it will automatically indent the next line like this:
<cfif this eq that>
|
When I turn auto indent off it will leave the cursor back at the far left, which would be great, but a lot of times my code is already indented:
<cfif this eq that>
|
What I want is it to leave it where it is currently indented to, no more, no less. Like this:
<cfif this eq that>
|
Any suggestions? Thanks!
There may be other ways to make this work for you.
But, you can edit the regex string in ColdFusion.tmPreferences file under
<key>increaseIndentPattern</key>
Just add cfif and cfelse to the list
|link|meta|param|cfif|cfelse
When there is an update to the ColdFusion package though, you may have to edit again.
Edit: Make sure to update the package to the latest version. The single line tags like cfargument should not indent as expected in the updated version.
Although what you would like does not seem to be possible at the moment, see ST2 forum (maybe you posted that?)
A slightly absurd workaround that may work for you, (seems to work for me). Go to View>Syntax>Java now the auto indention should do as you please - you may lose bracket tag matching (+other things?), syntax checking may be a bit nuts (you can always flip back if necessary, try other syntax stuff), and the colour scheme will change a little, but it seems to work.
Take a look at the settings in Sublime, there is one called 'smart_indent'.
The description for this setting is:
Makes auto indent a little smarter, e.g., by indenting the next line
after an if statement in C. Requires auto_indent to be enabled.
Found some more info in the Sublime Documentation.

coldfusion IIF error - Invalid CFML construct found

I am getting an an error "Invalid CFML construct found"
iif(stImages[id][1]["seolink"] is not "", stImages[id][1]["seolink"], stImages[id][1]["url"]) />
what i am doing here wrong?
Try:
iif(stImages[id][1]["seolink"] is not "", DE(stImages[id][1]["seolink"]), DE(stImages[id][1]["url"])) />
For those readers playing from home (as it were), IIF can be an unruly beast because of the double evaluation it does. So
#IIF(myVal EQ "", "thisThing", "thatThing")#
LOOKS like it will simply return the first or second strings, but in fact it will return the content of the VARIABLES "thisThing" or "thatThing" (or throw an error that they don't exist). So say it with me: "IIF() and DE() GO TOGETHER LIKE MUTUALLY BENEFICIAL PARASITIC LIFEFORMS". "DE" as in "Delayed Evaluation". So if you want the above statement to return the first or second string, you need:
#IIF(myVal EQ "", DE("thisThing"), DE("thatThing"))#
Now, you can certainly use this feature to evaluate a field twice and NOT use "DE()", but that means you're using some kind of dynamic variable name, and it could be argued that doing that isn't best practice. Not that I haven't done that exact thing, but it should be copiously commented, because if you don't the person who maintains the code after you will probably want to kill you.
By the way, there's no mystery to "DE()". These two statements are equivalent:
#DE("thisThing")#
#"""thisThing"""#
See what's going on? "DE()" simply puts double quotes around something. So one set of quotes gets "stripped off" the first time it gets evaluated, and then the quoted string gets returned from the function. Clear as mud?
See why people don't like IIF? It's very handy in certain situations, but is a contextual mess and contributes to code that makes people go "HWUUUH??" So that's why people say to avoid it if possible.
I would avoid iif where you can,
iif(stImages[id][1]["seolink"] is not "", DE(stImages[id][1]["seolink"]), DE(stImages[id][1]["url"])) />
<cfif stImages[id][1]["seolink"] is not "">#stImages[id][1]["seolink"]#<cfelse>#stImages[id][1]["url"]#</cfif>
or if you have ColdFusion 9
<cfset stImages[id][1]["seolink"] is not "" ? #stImages[id][1]["seolink"]# : #stImages[id][1]["url"]# />

Using hyphens in argument names

I am working with CFWheels and jquery mobile and am trying to pass some jquerymobile settings into a linkto call (mainly the data-icon attribute. I never new this before, but it appears to be that ColdFusion doesn't allow hyphens in argument names. My call is as follows:
<cfset contentFor(actioncontent=linkTo(text='Login', route='login', data-icon='check')) />
CFBuilder and Railo throw an error on the hyphen. The Railo error is:
invalid assignment left-hand side (railo.transformer.bytecode.op.OpDouble)
So my questions is: am I correct in saying that hyphens are not allowed in argument names? Also if they are not allowed, is there a way to get the hyphen through or do I just have to create the anchor tag?
try using quotes 'data-icon' or doublequotes "data-icon"
It's being interpreted as a minus not a dash
You can get this to work on Railo and Adobe's CF by creating a struct first and sending it in the argument collection. Otherwise, it will only work on Railo.
Example:
<cfscript>
args = {controller="form",
'data-role'="button",
'data-theme'="c",
text="I Accept"};
</cfscript>
#linkTo(argumentCollection=args)#
My quick hack is this:
#replace(linkTo(text="I accept", route="dashboard"),"<a ","<a data-role='button' ","ALL")#
(emphasis on the work hack - not ideal, but much easier than passing in the argumentCollection).