29 February ColdFusion bug

Written on 9 March 2012, 10:57pm

Tagged with: , ,

This is just to log a funny bug I encountered a few days ago, on the 29th of February 2012. There was a piece of code that was comparing if a certain date is older than a year or not.
The algorithm to compare the date was creating the ‘one-year-ago date’ by substracting one unit from the current year. Something like:

<cfset aYearAgo = CreateDate(year-1,month,day)>

Obviously, this algorithm was failing on the 29th of February on the leap years (like 2012).
The solution is quite simple: instead of substracting one unit from the year, substract 365 days from the current date, using Coldfusion’s dateAdd function:

<cfset aYearAgo = DateAdd('d', -365, Now())> 
Image: Smashing Magazine’s Desktop Wallpaper Calendar February 2012

Cfdocument – different behavior in CF7 vs CF8

Written on 26 October 2011, 02:26pm

Tagged with: , ,

The simple code below should write a PDF file on disk. This file should contain an image and two lines of text – next to the image (ignore the use of tables for layout 😛 ):

<cfsetting enablecfoutputonly="yes" showdebugoutput="no">

<cfoutput>
<cfdocument filename="output#Left(server.ColdFusion.ProductVersion,1)#.pdf" 
		format="pdf" overwrite="yes">
	<cfdocumentsection marginleft="1">
        <table>
            <tr>
                <td><img src='../images/image.gif'></td>
                <td>This is a simple text<br>spanning on two lines.</td>
            </tr>
        </table>
    </cfdocumentsection>
</cfdocument>
</cfoutput>

The result is quite different in ColdFusion 7 vs ColdFusion 8, as the following image shows:

In CF8, the PDF text and image appear visible smaller than in CF7.
Now the strange part: if I add unit attribute to cfdocument tag (with any value, ‘cm’ or ‘in’) – the CF8 version shows exactly the same size as CF7.

Anyone has any idea why this happens?

CF 8 bug: ColdFusion injecting cfscript in HTML head

Written on 20 July 2011, 02:13pm

Tagged with: , ,

I recently encountered the following ColdFusion problem:
I had a HTML page where the head node contained an attribute: <head lang="fr">
The same page was also using some cfform tags.
On the CF 8 server, ColdFusion automatically injects two <script> statements immediately after <head, but ignoring any other attribute. So, in our case, the resulting HTML code was:

<head <script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>
lang="fr">

Useless to say, this was breaking a lot of things in the design and the validation of the page.
(more…)