Changeset 294

Show
Ignore:
Timestamp:
12/25/06 18:49:31 (2 years ago)
Author:
scorfield
Message:

Fixes #163 by creating a centralized function to canonicalize a path that actually does it correctly!

Location:
framework/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • framework/trunk/fuseboxApplication.cfc

    r293 r294  
    6060                                        hint="I am FUSEBOX_CALLER_PATH." /> 
    6161                 
    62                 <!--- fixes ticket 54 ---> 
     62                <!--- fixes ticket 163 ---> 
    6363                <cfset var myVersion = "5.0.1.#REReplace('$LastChangedRevision$','[^0-9]','','all')#" /> 
    6464 
     
    7575                <cfset variables.coreRoot = replace(getDirectoryFromPath(getCurrentTemplatePath()),"\","/","all") /> 
    7676 
    77                 <cfset this.approotdirectory = normalizePartialPath(arguments.callerPath) & normalizePartialPath(arguments.appPath) /> 
    78                 <!--- remove pairs of directory/../ to form canonical path: ---> 
    79                 <cfloop condition="find('/../',this.approotdirectory) gt 0"> 
    80                         <cfset this.approotdirectory = REreplace(this.approotdirectory,"[^\.:/]*/\.\./","") /> 
    81                 </cfloop> 
     77                <cfset this.approotdirectory = getCanonicalPath(normalizePartialPath(arguments.callerPath) & normalizePartialPath(arguments.appPath)) /> 
     78 
    8279                <!--- this works on all platforms: ---> 
    8380                <cfset this.osdelimiter = "/" /> 
     
    10611058        </cffunction> 
    10621059         
     1060        <cffunction name="getCanonicalPath" returntype="string" access="public" output="false"  
     1061                                hint="I return a canonical file path (with all /../ sections resolved)."> 
     1062                <cfargument name="path" type="string" required="true"  
     1063                                        hint="I am the path to resolve." /> 
     1064                 
     1065                <cfset var resolvedPath = arguments.path /> 
     1066                <cfset var leadingSlash = left(resolvedPath,1) is "/" /> 
     1067                <cfset var trailingSlash = right(resolvedPath,1) is "/" /> 
     1068                <cfset var segment = ""/> 
     1069                <cfset var j = 1 /> 
     1070                <cfset var n = 0 /> 
     1071                <cfset var pathParts = arrayNew(1) /> 
     1072                <cfset var delimiter = "" /> 
     1073 
     1074                <!--- remove pairs of directory/../ --->                 
     1075                <cfloop list="#resolvedPath#" delimiters="/" index="segment"> 
     1076                        <cfif segment is "."> 
     1077                                <!--- just ignore this ---> 
     1078                        <cfelseif segment is ".."> 
     1079                                <cfif j gt 1 and pathParts[j-1] is not ".."> 
     1080                                        <cfset j = j - 1 /> 
     1081                                <cfelse> 
     1082                                        <cfset pathParts[j] = segment /> 
     1083                                        <cfset j = j + 1 /> 
     1084                                </cfif> 
     1085                        <cfelse> 
     1086                                <cfset pathParts[j] = segment /> 
     1087                                <cfset j = j + 1 /> 
     1088                        </cfif> 
     1089                </cfloop> 
     1090                 
     1091                <!--- rebuild the path ---> 
     1092                <cfif leadingSlash> 
     1093                        <cfset delimiter = "/" /> 
     1094                </cfif> 
     1095                <cfset resolvedPath = "" /> 
     1096                <cfset n = j - 1 /> 
     1097                <cfloop from="1" to="#n#" index="j"> 
     1098                        <cfset resolvedPath = resolvedPath & delimiter & pathParts[j] /> 
     1099                        <cfset delimiter = "/" /> 
     1100                </cfloop> 
     1101                <cfif trailingSlash> 
     1102                        <cfset resolvedPath = resolvedPath & "/" /> 
     1103                </cfif> 
     1104 
     1105                <cfreturn resolvedPath /> 
     1106                 
     1107        </cffunction> 
     1108         
    10631109        <cffunction name="normalizePartialPath" returntype="string" access="public" output="false"  
    1064                                 hint=""> 
     1110                                hint="I return a normalized file path (that has / instead of \ and ends with /)."> 
    10651111                <cfargument name="partialPath" type="string" required="true"  
    1066                                         hint="" /> 
     1112                                        hint="I am the path to normalize." /> 
    10671113                 
    10681114                <cfset var unixPath = replace(arguments.partialPath,"\","/","all") /> 
  • framework/trunk/fuseboxCircuit.cfc

    r292 r294  
    6969                        </cfif> 
    7070                </cfif> 
    71                 <!--- remove pairs of directory/../ to form canonical path: ---> 
    72                 <cfloop condition="find('/../',variables.fullPath) gt 0"> 
    73                         <cfset variables.fullPath = REreplace(variables.fullPath,"[^\.:/]*/\.\./","") /> 
    74                 </cfloop> 
     71                 
     72                <cfset variables.fullPath = variables.fuseboxApplication.getCanonicalPath(variables.fullPath) /> 
     73 
    7574                <!--- 
    7675                        this was not correctly normalized prior to ticket 139 but it didn't really matter 
  • framework/trunk/fuseboxPlugin.cfc

    r292 r294  
    110110                                                                                                                this.path,arguments.fbApp.getApplicationRoot()) /> 
    111111                        </cfif> 
    112                         <!--- remove pairs of directory/../ to form canonical path: ---> 
    113                         <cfloop condition="find('/../',this.rootpath) gt 0"> 
    114                                 <cfset this.rootpath = REreplace(this.rootpath,"[^\.:/]*/\.\./","") /> 
    115                         </cfloop> 
     112                         
     113                        <cfset this.rootpath = arguments.fbApp.getCanonicalPath(this.rootpath) /> 
    116114                         
    117115                        <cfset variables.parameters = arguments.pluginXML.xmlChildren /> 
  • framework/trunk/myFusebox.cfc

    r293 r294  
    1616<cfcomponent hint="I provide the per-request myFusebox data structure and some convenience methods."> 
    1717        <cfscript> 
    18         // fixes ticket 54 
     18        // fixes ticket 163 
    1919        this.version.runtime     = "5.0.1.#REReplace('$LastChangedRevision$','[^0-9]','','all')#"; 
    2020