DEV Community

Cover image for ColdFusion Dump Alternative
James Moberg
James Moberg

Posted on

ColdFusion Dump Alternative

The cfdump tag (AKA cfscript "writedump" function) outputs the contents of a variable of any type for debugging purposes. The variable can be as simple as a string or as complex as a cfc component instance.

If you've ever used this and then viewed the source code, you'll see that there's an extreme amount of generated whitespace. I'm not sure if this has ever been reviewed & optimized, but it is something that can be improved. There haven't been many updates to it since CF9 while CF8 seems to be the version that received the most updates.

  • ColdFusion 9: Added the attribute abort.
  • ColdFusion 8: Added the show, format, hide, keys, metainfo, output, and showUDFs attributes.
  • ColdFusion MX 7: Added the top attribute.
  • ColdFusion MX 6.1: Added the ability to dump COM objects; it displays the methods and Get and Put properties typeinfo information for the object.
  • ColdFusion 5: Introduced as a new built-in tag

I created a wrapper that removed the whitespace, but wasn't happy with it and then wrote my own cf_dumplite function that was much faster, generated less unnecessary whitespace, didn't inline JS & CSS and provided more options and better control over the values being outputted (ie, PCI compliance). If you tend to have the server send CFDump via email and include the FORM post, you'll often realize that passwords, credit card numbers or other sensitive information is being passed electronically in a non-secure manner. Hackers now don't need to hack your web application... they only need to gain access to your email account. If you send this data to a gmail account, your visitor's sensitive information has now been indexed by the world's #1 advertiser.

As an ACF developer, I was always a little jealous that Railo/Lucee went the extra mile and additionally displayed the datatype and had summaries regarding quantity of keys. While researching how to best identify data types in ColdFusion (which can seem like a slippery slope), I discovered Alexander Kwaschny's improved Dump tag called cf_dump that "improves the native cfdump tag by providing more insight".

"The <cfdump> tag is very handy to debug data. However, the output of it, especially in Adobe ColdFusion, unfortunately is very sparse. And while Lucee does way better here, there is still room for improvement. This custom tag <cf_dump> is written from scratch, offers more insight and usually renders faster than the native (ACF) cfdump."

This open-source (MIT license) third-party solution is pretty awesome:

  • Identifies & color-codes the datatype
  • Displays a hint regarding the string, key, array or query row count/length
  • Can highlight leading & trailing spaces (wsWarning argument; options: true/false/key/value)
  • Can preserve whitespace (option; perfect for previewing format-sensitive data)
  • Capability to display private CFC variables (requires adding a dump method)
  • Outputs byte arrays with each byte as hex in an array (w/byteMax option)
  • Supports blacklisting specific keys & fields
  • Prevent recursively dumping circular references (Yikes! The ColdFusion 10-2023 output for this is troubling. Lucee does it right.)
  • Expand/collage by clicking col/row headers (JS/CSS is only included once)
    • NOTE: It doesn't seem that you can start with the dump in a "collapsed" mode
  • Option to embed css/JS content (in case used with cfsavecontent)
  • Separate cf_dumpmail tag for sending the dump via email
  • Global override by defining a magic "request" variable.

Depending on my needs, I switch between my dumplite tag and CF_Dump. I'll use CF_Dump when I need to identify data types, verify spaces or preserve whitespace. I use this a lot when writing cross-platform compliant code where I want to test whether Adobe ColdFusion and Lucee are reliably returning the same expected values.

NOTE: I shared a discovery back in April 2022 (entitled CFDump ShowUDFs Behavior) where Adobe & Lucee both process the showUDFs attribute differently. I used the CF_Dump tag to standardize the output.

Anyway, check out CF_Dump and use it wherever CFDump or writedump is used. (NOTE: You can use CFTags in cfscript. ex: cf_dump(var=CGI);).

https://github.com/kwaschny/cf_dump

Here's some screenshots of the generated output.

struct dump

struct dump

array dump

array dump

query dump

query dump

string with preserved whitespaces

string with preserved whitespaces

Component dump with public & private fields

Component dump with public & private fields

java object dump

java object dump

Byte array (with encoding) dump

Byte array (with encoding) dump

Dump with blacklisted keys

Dump with blacklisted keys

Dump with circular references

Dump with circular references

Exception dump

Exception dump

Top comments (2)

Collapse
 
giancarlogomez profile image
Giancarlo Gomez

Thank you for sharing James!

Collapse
 
jack_p72 profile image
Jack Poe

This is the kind of stuff that Adobe should be working on in future editions of CF