Mark Drew (Redux)- cf_etc...

a compendium of railo, cfml, cfeclipse and technology topics

Mark Drew (Redux)- cf_etc...

Strange expandPath bug in ColdFusion 8

January 23, 2009 ·

I found something that I am not sure if it is a bug or a "feature" whilst developing some functionality in our CMS. Essentially imagine you have the following directory layout:

  • index.cfm
  • level1/
    • level2/
      • index.cfm
In the root index.cfm I want to expand the path to level2, that is, get the full folder path of "path2", you would do something like:
<cfset mypath1 = "/level1/level2">
   <cfdump var="#expandPath(mypath1)#">

Which (in my case) returns: /Library/WebServer/Documents/scratch/level1/level2

BUT if you add the forward slash to the path:
<cfset mypath2 = "/level1/level2/">
   <cfdump var="#expandPath(mypath2)#">

You get: /Library/WebServer/Documents/scratch/level1/level2/index.cfm/ ?!
Where did "index.cfm/" come from? I can understand how that might be useful in 0.1% of cases but not when you are simply trying to find the path to the folder. If you remove the index.cfm from the folder it all works fine.

Shome mishtake, shurely?

Tags: coldfusion

7 responses

  • 1 Ben Nadel // Jan 23, 2009 at 5:59 PM

    That's really weird!
  • 2 tony petruzzi // Jan 23, 2009 at 6:53 PM

    what webserver and operating system are you running? I just tried this out on my cf server running cf8.01 at level hf801-71557 on windows 2003 (all patches installed) and IIS.

    this bug was not reproducible.

    it could also be a mapping issue.
  • 3 Mark Mandel // Jan 23, 2009 at 9:49 PM

    Mark,

    I've totally seen this before.

    I'm willing to guess you're on Apache as a webserver?

    If I remember correct, expandPath() will somehow look to your default webserver page mappings, and attempt to append their values to your expandPath(). It's weird, and bizarre, and I don't know WHY, but it's definitely reproducible.
  • 4 Gary Funk // Jan 24, 2009 at 5:37 PM

    Under IIS:

    D:\www\rk7\level1\level2\

    Under Apache:

    D:\www\rk7\level1\level2\index.cfm\
  • 5 Pierre Paridans // Jan 26, 2009 at 9:39 AM

    Could it be related to mod_rewrite (which is only available under Apache of course)?
  • 6 Dennis Belmont // Mar 2, 2010 at 3:52 PM

    I've got an even stranger one. I've got a site in a virtual hosting environment. When I'm using ExpandPath(), it's returning the path to the *ColdFusion* server, not to my website. When I should be getting this:

    D:\inetpub\ensco

    I'm getting this:

    C:\ColdFusion8\wwwroot\

    Has anyone seen this before? Any ideas?
  • 7 david // Aug 17, 2010 at 9:45 PM

    Found the fix over @ http://kaijaks.co.uk/blog/nick/2009/04/30/expandpath-bug-in-coldfusion-8

    Add a "/" mapping in CFADmin to the web root of your site

    Made my Apache expand path errors go away