From be31f84196f8b72744692b62519a0cdfdcff68b5 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 9 May 2015 21:53:38 -0700 Subject: [PATCH] Fix #323 on master for 3.0.1/2 Using getContextRoot() & ... for path. --- framework/one.cfc | 164 +++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/framework/one.cfc b/framework/one.cfc index 21c2249a..8a9a4c98 100644 --- a/framework/one.cfc +++ b/framework/one.cfc @@ -1,5 +1,5 @@ component { - variables._fw1_version = "3.0.1"; + variables._fw1_version = "3.0.2"; /* Copyright (c) 2009-2015, Sean Corfield, Marcin Szczepanski, Ryan Cogswell @@ -35,7 +35,7 @@ component { variables.magicApplicationController = '[]'; variables.magicApplicationAction = '__'; variables.magicBaseURL = '-[]-'; - + public void function abortController() { request._fw1.abortController = true; internalFrameworkTrace( 'abortController() called' ); @@ -50,11 +50,11 @@ component { return listLen( action, variables.framework.subsystemDelimiter ) > 1 || right( action, 1 ) == variables.framework.subsystemDelimiter; } - + public void function addRoute( any routes, string target, any methods = [ ], string statusCode = '' ) { if ( !isArray( routes ) ) routes = [ routes ]; if ( !isArray( methods ) ) methods = [ methods ]; - param name="variables.framework.routes" default="#[ ]#"; + param name="variables.framework.routes" default="#[ ]#"; if ( len( statusCode ) ) target = statusCode & ':' & target; for ( var route in routes ) { if ( arrayLen( methods ) ) { @@ -143,7 +143,7 @@ component { var cosmeticAction = getFullyQualifiedAction( action ); var isHomeAction = cosmeticAction == getFullyQualifiedAction( variables.framework.home ); var isDefaultItem = getItem( cosmeticAction ) == variables.framework.defaultItem; - + var initialDelim = '?'; var varDelim = '&'; var equalDelim = '='; @@ -169,11 +169,11 @@ component { ses = true; } var curDelim = varDelim; - + if ( usingSubsystems() && getSubsystem( cosmeticAction ) == variables.framework.defaultSubsystem ) { cosmeticAction = getSectionAndItem( cosmeticAction ); } - + if ( len( queryString ) ) { // extract query part and anchor from query string: q = find( '?', queryString ); @@ -207,7 +207,7 @@ component { extraArgs = listChangeDelims( extraArgs, '/', '&=' ); } } - + if ( ses ) { if ( isHomeAction && extraArgs == '' ) { basePath = path; @@ -226,7 +226,7 @@ component { basePath = path & initialDelim & variables.framework.action & equalDelim & cosmeticAction; } } - + if ( extraArgs != '' ) { basePath = basePath & curDelim & extraArgs; curDelim = varDelim; @@ -334,7 +334,7 @@ component { public string function getAction() { return variables.framework.action; } - + /* * returns the base URL for redirects and links etc * can be overridden if you need to modify this per-request @@ -342,7 +342,7 @@ component { public string function getBaseURL() { return variables.framework.baseURL; } - + /* * returns whatever the framework has been told is a bean factory * this will return a subsystem-specific bean factory if one @@ -367,7 +367,7 @@ component { } return getDefaultBeanFactory(); } - + /* * return the framework configuration */ @@ -405,7 +405,7 @@ component { return variables.framework.defaultSubsystem; } - + /* * override this to provide your environment selector */ @@ -430,7 +430,7 @@ component { public array function getFrameworkTrace() { return request._fw1.trace; } - + /* * return an action with all applicable parts (subsystem, section, and item) specified * using defaults from the configuration or request where appropriate @@ -449,45 +449,45 @@ component { public string function getHostname() { return createObject( 'java', 'java.net.InetAddress' ).getLocalHost().getHostName(); } - + /* * return the item part of the action */ public string function getItem( string action = request.action ) { return listLast( getSectionAndItem( action ), '.' ); } - - + + /* * return the current route (if any) */ public string function getRoute() { return structKeyExists( request._fw1, 'route' ) ? request._fw1.route : ''; } - - + + /* * return the configured routes */ public array function getRoutes() { return variables.framework.routes; } - + /* * return the resource route templates */ public array function getResourceRouteTemplates() { return variables.framework.resourceRouteTemplates; } - + /* * return the section part of the action */ public string function getSection( string action = request.action ) { return listFirst( getSectionAndItem( action ), '.' ); } - - + + /* * return the action without the subsystem */ @@ -520,8 +520,8 @@ component { return sectionAndItem; } - - + + /* * return the subsystem part of the action */ @@ -550,7 +550,7 @@ component { return application[ variables.framework.applicationKey ].subsystemFactories[ subsystem ]; } - + /* * return the (optional) configuration for a subsystem */ @@ -627,9 +627,9 @@ component { // the requested template. // NOTE: for unhandledPaths, we make the list into an escaped // regular expression so we match on subdirectories, meaning - // /myexcludepath will match '/myexcludepath' and all subdirectories + // /myexcludepath will match '/myexcludepath' and all subdirectories return listFindNoCase( variables.framework.unhandledExtensions, - listLast( targetPath, '.' ) ) || + listLast( targetPath, '.' ) ) || REFindNoCase( '^(' & variables.framework.unhandledPathRegex & ')', targetPath ); } @@ -672,7 +672,7 @@ component { failure( exception, event, false, true ); return; } - + // record details of the exception: if ( structKeyExists( request, 'action' ) ) { request.failedAction = request.action; @@ -695,7 +695,7 @@ component { } // setup the new controller action, based on the error action: request._fw1.controllers = [ ]; - + if ( structKeyExists( variables, 'framework' ) && structKeyExists( variables.framework, 'error' ) ) { request.action = variables.framework.error; } else { @@ -815,7 +815,7 @@ component { internalFrameworkTrace( 'onMissingView() called' ); out = onMissingView( request.context ); } - + buildLayoutQueue(); for ( i = 1; i <= arrayLen(request._fw1.layouts); i = i + 1 ) { if ( structKeyExists(request, 'layout') && !request.layout ) { @@ -856,11 +856,11 @@ component { // ensure flash context cannot override request action: request.context[variables.framework.action] = request.action; - if ( isUnhandledRequest( targetPath ) ) { + if ( isUnhandledRequest( targetPath ) ) { structDelete(this, 'onRequest'); structDelete(variables, 'onRequest'); structDelete(this, 'onRequestEnd'); - structDelete(variables, 'onRequestEnd'); + structDelete(variables, 'onRequestEnd'); if ( !variables.framework.unhandledErrorCaught ) { structDelete(this, 'onError'); structDelete(variables, 'onError'); @@ -881,7 +881,7 @@ component { setupRequestDefaults(); setupSessionWrapper(); } - + // populate() may be invoked inside controllers public any function populate( any cfc, string keys = '', boolean trustKeys = false, boolean trim = false, boolean deep = false, any properties = '' ) { var props = isSimpleValue( properties ) ? request.context : properties; @@ -893,7 +893,7 @@ component { var args = { }; args[ property ] = props[ property ]; if ( trim && isSimpleValue( args[ property ] ) ) args[ property ] = trim( args[ property ] ); - // cfc[ 'set'&property ]( argumentCollection = args ); // ugh! no portable script version of this?!?! + // cfc[ 'set'&property ]( argumentCollection = args ); // ugh! no portable script version of this?!?! setProperty( cfc, property, args ); } catch ( any e ) { onPopulateError( cfc, property, props ); @@ -985,10 +985,10 @@ component { baseQueryString = listAppend( baseQueryString, key & '=' & urlEncodedFormat( request.context[ key ] ), '&' ); } } - + } } - + if ( baseQueryString != '' ) { if ( queryString != '' ) { if ( left( queryString, 1 ) == '?' || left( queryString, 1 ) == '##' ) { @@ -1000,7 +1000,7 @@ component { } else { baseQueryString = queryString; } - + var targetURL = buildURL( action, path, baseQueryString ); if ( preserveKey != '' && variables.framework.maxNumContextsPreserved > 1 ) { if ( find( '?', targetURL ) ) { @@ -1062,7 +1062,7 @@ component { public void function renderData( string type, any data, numeric statusCode = 200 ) { request._fw1.renderData = { type = type, data = data, statusCode = statusCode }; } - + /* * call this from your setupApplication() method to tell the framework * about your bean factory - only assumption is that it supports: @@ -1087,7 +1087,7 @@ component { request._fw1.overrideLayoutAction = validateAction( action ); request._fw1.suppressOtherLayouts = suppressOtherLayouts; } - + /* * call this from your setupSubsystem() method to tell the framework * about your subsystem-specific bean factory - only assumption is that it supports: @@ -1149,14 +1149,14 @@ component { * and handle it yourself */ public void function setupTraceRender( string output = 'html' ) { } - + /* * override this to provide pre-rendering logic, e.g., to * populate the request context with globally required data * you do not need to call super.setupView() */ public void function setupView( struct rc ) { } - + /* * use this to override the default view */ @@ -1170,7 +1170,7 @@ component { public boolean function usingSubsystems() { return variables.framework.usingSubsystems; } - + /* * view() may be invoked inside views and layouts * returns the UI generated by the named view @@ -1194,9 +1194,9 @@ component { return onMissingView( request.context ); } } - + // THE FOLLOWING METHODS SHOULD ALL BE CONSIDERED PRIVATE / UNCALLABLE - + private void function autowire( any cfc, any beanFactory ) { var setters = findImplicitAndExplicitSetters( cfc ); for ( var property in setters ) { @@ -1208,7 +1208,7 @@ component { } } } - + private void function buildLayoutQueue() { var siteWideLayoutBase = request.base & getSubsystemDirPrefix( variables.framework.siteWideLayoutSubsystem ); var testLayout = 0; @@ -1217,10 +1217,10 @@ component { var section = request.section; var item = request.item; var subsystembase = ''; - + request._fw1.layouts = [ ]; var cascadeLayouts = true; // default can be overridden via setLayout() second argument - + // has layout been overridden? if ( structKeyExists( request._fw1, 'overrideLayoutAction' ) ) { subsystem = getSubsystem( request._fw1.overrideLayoutAction ); @@ -1230,7 +1230,7 @@ component { if ( structKeyExists( request._fw1, 'suppressOtherLayouts' ) ) { cascadeLayouts = !request._fw1.suppressOtherLayouts; structDelete( request._fw1, 'suppressOtherLayouts' ); - } + } } subsystembase = request.base & getSubsystemDirPrefix( subsystem ); internalFrameworkTrace( 'building layout queue', subsystem, section, item ); @@ -1276,7 +1276,7 @@ component { var section = request.section; var item = request.item; var subsystembase = ''; - + // has view been overridden? if ( structKeyExists( request._fw1, 'overrideViewAction' ) ) { subsystem = getSubsystem( request._fw1.overrideViewAction ); @@ -1311,8 +1311,8 @@ component { } return cache.fileExists[ filePath ]; } - - + + private string function cfcFilePath( string dottedPath ) { if ( dottedPath == '' ) { return '/'; @@ -1331,7 +1331,7 @@ component { out.println( "FW/1: DEPRECATED: " & message ); } } - + private void function doController( struct tuple, string method, string lifecycle ) { var cfc = tuple.controller; if ( structKeyExists( cfc, method ) ) { @@ -1354,11 +1354,11 @@ component { internalFrameworkTrace( 'no #lifecycle# controller to call', tuple.subsystem, tuple.section, method ); } } - + private void function dumpException( any exception ) { writeDump( var = exception, label = 'Exception - click to expand', expand = false ); } - + private void function ensureNewFrameworkStructsExist() { var framework = application[variables.framework.applicationKey]; @@ -1388,7 +1388,7 @@ component { } writeOutput( '#exception.message#' ); } - + writeOutput( '

#exception.detail# (#exception.type#)

' ); dumpException(exception); @@ -1526,7 +1526,7 @@ component { var subsystemUnderscore = replace( subsystemDir, '/', '_', 'all' ); var componentKey = subsystemUnderscore & section; var beanName = section & "controller"; - + if ( !structKeyExists( cache.controllers, componentKey ) ) { lock name="fw1_#application.applicationName#_#variables.framework.applicationKey#_#componentKey#" type="exclusive" timeout="30" { if ( !structKeyExists( cache.controllers, componentKey ) ) { @@ -1566,14 +1566,14 @@ component { } // else "return null" effectively } - + private any function getController( string section, string subsystem = getDefaultSubsystem() ) { var _controller_fw1 = getCachedController( subsystem, section ); if ( !isNull( _controller_fw1 ) ) { return _controller_fw1; } } - + private string function getNextPreserveKeyAndPurgeOld() { var nextPreserveKey = ''; var oldKeyToPurge = ''; @@ -1601,11 +1601,11 @@ component { } return nextPreserveKey; } - + private string function getPreserveKeySessionKey( string preserveKey ) { return '__fw1' & preserveKey; } - + private any function getProperty( struct cfc, string property ) { if ( structKeyExists( cfc, 'get#property#' ) ) return evaluate( 'cfc.get#property#()' ); } @@ -1618,7 +1618,7 @@ component { return subsystem & '/'; } - + private void function injectFramework( any cfc ) { var args = { }; if ( structKeyExists( cfc, 'setFramework' ) || structKeyExists( cfc, 'onMissingMethod' ) ) { @@ -1629,7 +1629,7 @@ component { evaluate( 'cfc.setFramework( argumentCollection = args )' ); } } - + private void function internalFrameworkTrace( string message, string subsystem = '', string section = '', string item = '' ) { if ( request._fw1.doTrace ) { try { @@ -1662,7 +1662,7 @@ component { } return response; } - + private string function internalView( string viewPath, struct args = { } ) { var rc = request.context; var $ = { }; @@ -1677,7 +1677,7 @@ component { } return response; } - + private boolean function isFrameworkInitialized() { return structKeyExists( variables, 'framework' ) && structKeyExists( application, variables.framework.applicationKey ); @@ -1714,7 +1714,7 @@ component { return customizeViewOrLayoutPath( pathInfo, type, '#pathInfo.base##type#s/#pathInfo.path#.cfm' ); } - + private struct function processRouteMatch( string route, string target, string path, string httpMethod ) { var regExCache = isFrameworkInitialized() ? application[ variables.framework.applicationKey ].cache.routes.regex : { }; var cacheKey = hash( route & target ); @@ -1817,7 +1817,7 @@ component { var target = '/#subsystemResourceTarget#/#routeTemplate.method#'; if ( structKeyExists( routeTemplate, 'includeId' ) && routeTemplate.includeId ) target &= '/id/:id'; if ( structKeyExists( routeTemplate, 'targetSuffix' ) ) target &= routeTemplate.targetSuffix; - target &= targetAppend; + target &= targetAppend; routePack[ route ] = target; } arrayAppend( routes, routePack ); @@ -1895,7 +1895,7 @@ component { } } if ( path == 'useCgiScriptName' ) { - path = request._fw1.cgiScriptName; + path = getContextRoot() & request._fw1.cgiScriptName; if ( variables.framework.SESOmitIndex ) { path = getDirectoryFromPath( path ); omitIndex = true; @@ -1937,7 +1937,7 @@ component { // session scope not enabled, do nothing } } - + private string function saveFlashContext( string keys ) { var curPreserveKey = getNextPreserveKeyAndPurgeOld(); var preserveKeySessionKey = getPreserveKeySessionKey( curPreserveKey ); @@ -1970,7 +1970,7 @@ component { } request.failedMethod = method; } - + private void function setProperty( struct cfc, string property, struct args ) { if ( listLen( property, '.' ) > 1 ) { var firstObjName = listFirst( property, '.' ); @@ -1987,7 +1987,7 @@ component { evaluate( 'cfc.set#property#( argumentCollection = args )' ); } } - + private void function setupApplicationWrapper() { /* since this can be called on a reload, we need to lock it to prevent other threads @@ -2013,7 +2013,7 @@ component { isReload = false; framework.cache = frameworkCache; framework.subsystems = { }; - framework.subsystemFactories = { }; + framework.subsystemFactories = { }; application[variables.framework.applicationKey] = framework; } } @@ -2043,16 +2043,16 @@ component { setBeanFactory( ioc ); break; } - + // this will recreate the main bean factory on a reload: internalFrameworkTrace( 'setupApplication() called' ); setupApplication(); - + if ( isReload ) { /* it's possible that the cache got populated by another thread between resetting the cache above and the factory getting recreated by the user code in setupApplication() so we flush the cache - again here to be safe / paranoid! + again here to be safe / paranoid! */ frameworkCache = { }; frameworkCache.lastReload = now(); @@ -2062,9 +2062,9 @@ component { application[variables.framework.applicationKey].cache = frameworkCache; application[variables.framework.applicationKey].subsystems = { }; } - + } - + private void function setupFrameworkDefaults() { // default values for Application::variables.framework structure: @@ -2176,7 +2176,7 @@ component { } else { variables.framework.unhandledPaths = '/flex2gateway'; variables.framework.unhandledPathRegex = '/flex2gateway'; - } + } if ( !structKeyExists( variables.framework, 'unhandledErrorCaught' ) ) { variables.framework.unhandledErrorCaught = false; } @@ -2276,7 +2276,7 @@ component { internalFrameworkTrace( 'route matched - #routeMatch.route# - #pathInfo#' ); pathInfo = rereplace( routeMatch.path, routeMatch.pattern, routeMatch.target ); if ( routeMatch.redirect ) { - location( pathInfo, false, routeMatch.statusCode ); + location( pathInfo, false, routeMatch.statusCode ); } else { request._fw1.route = routeMatch.route; } @@ -2336,7 +2336,7 @@ component { request.subsystembase = request.base & getSubsystemDirPrefix( request.subsystem ); request.section = getSection( request.action ); request.item = getItem( request.action ); - + if ( runSetup ) { if ( usingSubsystems() ) { controller( variables.magicApplicationSubsystem & variables.framework.subsystemDelimiter & @@ -2387,7 +2387,7 @@ component { ioc.setParent( getDefaultBeanFactory() ); setSubsystemBeanFactory( subsystem, ioc ); } - + internalFrameworkTrace( 'setupSubsystem() called', subsystem ); setupSubsystem( subsystem ); } @@ -2411,5 +2411,5 @@ component { raiseException( type='FW1.viewNotFound', message="Unable to find a view for '#request.action#' action.", detail="'#request.missingView#' does not exist." ); } - + }