AdobeStock_455007340

Another Portability Gotcha

Home » Another Portability Gotcha

The Windows to Linux port tripped me up again, and this is an embarrassing one because I have written about just this issue, and apparently ignored my own advice. Nothing major, in fact it went unnoticed for several months (as this is on the first site that I ported), but a gotcha nonetheless.
http://www.cffaq.com/ has a breadcrumb navigation element at the top of the page. I noticed this morning that no matter what page I was on, the breadcrumb only contained a “home” option (the default used if the breadcrumb creation code is unable to work out where in the site we are). The problem? I was using code that read CGI.PATH_TRANSLATED to determine the URL being processed. CGI.PATH_TRANSLATED is a path, and I was treating it as a list delimited by (and then doing a ListLast() to get just the file name portion of the path). The problem? Unix uses / (slash) and not (backslash), and so the entire CGI.PATH_TRANSLATED was being returned by ListLast() and that broke things.
Truth is, / would not have worked on Windows (just as does not on Linux), any solution to pathing problems really needs to be dynamic. One option might be to initialize variables on startup (perhaps based on SERVER.os.name) with the right values. Another option might be to use a UDF that took a path and returned it in some normalized format. There is no single right solution to this one, as long as you are cognizant of the problem and actually implement a solution.

4 responses to “Another Portability Gotcha”

  1. Sam Farmer Avatar
    Sam Farmer

    I’ve used the first approach you mention to determine the slash direction in the past and its worked well.

  2. cfguy Avatar
    cfguy

    Well why don’t you just add both and / to list functions delimiter attributes?

  3. Rob Brooks-Bilson Avatar
    Rob Brooks-Bilson

    Ben,
    You can use Java (wrapped as a UDF) to determine the file seperator for the system. See Christain Cantrell’s blog entry on the subject for an example:
    http://www.markme.com/cantrell/archives/002195.cfm

  4. seancorfield Avatar
    seancorfield

    I was going to suggest what cfguy did – put "/" into the list functions as the set of delimiters.
    Overall tho’, this highlights an interesting philosophical issue: should your website’s navigation structure match your file system structure?
    On some sites, the navigation matches the file system identically; on others (like macromedia.com) there’s a fuzzy mapping between the two – it matches in some places and not in others; on yet others (like any Fusebox site) the directory structure is totally hidden.

Leave a Reply