Sorcerer's Isle

expandPath bug in CF8

I've just encountered a very annoying bug with the expandPath function in CF8.

Take the following code:

<cfset MyDir = "."/> <cfloop index="i" from="1" to="5"> <cfset MyDir = expandPath(MyDir)/> <cfoutput><br/>#MyDir#</cfoutput> </cfloop>

Run the code through Railo and you will get exactly the right behaviour, with the current directory output five times:

C:\dev\scratch C:\dev\scratch C:\dev\scratch C:\dev\scratch C:\dev\scratch

Now go run the same code with CF8 - and this is what you get:

F:\ColdFusion8\wwwroot\scratch F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch\F:\ColdFusion8\wwwroot\scratch

It simply stacks the current directory onto the front each time. Very frustrating.


In order to get round this, I created a regular expression to pull off the last value of any directory containing more than one colon - this will work for Windows machines, but may need to be changed for Linux or MacOSX machines (if the bug affects these).

<cfif isDefined('Server.ColdFusion.ProductName') AND Server.ColdFusion.ProductName EQ 'ColdFusion Server' AND ListLen( MyDir ,':') GT 2> <cfset MyDir = REreplace( MyDir , "^.*([A-Z]:[^:]+)$" , "\1" )/> </cfif>
Posted:
16 August 2008, 17:23
Tags:
ColdFusion
CFML

There have been 3 comments.

James Netherton @ 2008-Aug-17 10:47
Weird - Write the same code using cfscript and it behaves properly.
Peter @ 2008-Aug-17 12:44
Odd.

It still doesn't work in cfscript for me.

I tried it with the following:
<cfscript>
MyDir = ".";

for ( i=1 ; i LTE 5 ; i=i+1 )
{
MyDir = expandPath(MyDir);
WriteOutput("<br/>#MyDir#");
}
</cfscript>
James Netherton @ 2008-Aug-17 16:02
Doh! Ignore me, I wasn't assigning MyDir to the result returned by expandpath in the loop.

Yep, it's a bug :)
Registered Members
If unregistered, leave blank.
If unregistered, leave blank.
Unregistered Guests
Identifies your comment
Not displayed publically. Allows new comment notifications, or for the blog owner to contact you.
Link your name back to your personal website.
Comment