Changeset 290

Show
Ignore:
Timestamp:
12/24/06 19:49:24 (2 years ago)
Author:
scorfield
Message:

Fixes #141 by adding strict check to <xfa> and allowing <parameter> with <xfa>.

Location:
framework/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • framework/trunk/fuseboxApplication.cfc

    r289 r290  
    9393                                        hint="I am the myFusebox data structure." /> 
    9494                 
    95                 <!--- fixes a bug in how ticket 73 was implemented ---> 
     95                <!--- fixes ticket 141 ---> 
    9696                <cfset var myVersion = "5.0.1.#REReplace('$LastChangedRevision$','[^0-9]','','all')#" /> 
    9797 
  • framework/trunk/myFusebox.cfc

    r289 r290  
    5151<cfcomponent hint="I provide the per-request myFusebox data structure and some convenience methods."> 
    5252        <cfscript> 
    53         // fixes a bug in how ticket 73 was implemented 
     53        // fixes ticket 141 
    5454        this.version.runtime     = "5.0.1.#REReplace('$LastChangedRevision$','[^0-9]','','all')#"; 
    5555           
  • framework/trunk/verbs/parameter.cfm

    r178 r290  
    5252        if (fb_.verbInfo.executionMode is "start") { 
    5353                // validate attributes 
    54                 // name - string - required, must be varname or varname.varname 
    55                 if (not structKeyExists(fb_.verbInfo.attributes,"name")) { 
    56                         fb_throw("fusebox.badGrammar.requiredAttributeMissing", 
    57                                                 "Required attribute is missing", 
    58                                                 "The attribute 'name' is required, for a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     54                // <parameter> is actually two verbs and behaves differently depending on its 
     55                // parent: 
     56                // - inside an <include>, it saves / sets variables for the duration of the 
     57                //   include just as it does inside a <do> directive 
     58                // - inside an <xfa>, it defines URL parameters to add to the XFA value 
     59                if (structKeyExists(fb_.verbInfo,"parent")) { 
     60 
     61                        if (fb_.verbInfo.parent.lexiconVerb is "include") { 
     62 
     63                                // name - string - required, must be varname or varname.varname 
     64                                if (not structKeyExists(fb_.verbInfo.attributes,"name")) { 
     65                                        fb_throw("fusebox.badGrammar.requiredAttributeMissing", 
     66                                                                "Required attribute is missing", 
     67                                                                "The attribute 'name' is required, for a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     68                                } 
     69                                fb_.match1 = REFind("[A-Za-z0-9_]*",fb_.verbInfo.attributes.name,1,true); 
     70                                fb_.match2 = REFind("[A-Za-z0-9_]*\.[A-Za-z0-9_]*",fb_.verbInfo.attributes.name,1,true); 
     71                                fb_.nameLen = len(fb_.verbInfo.attributes.name); 
     72                                if (fb_.match1.pos[1] eq 1 and fb_.match1.len[1] eq fb_.nameLen) { 
     73                                        fb_.name = "variables." & fb_.verbInfo.attributes.name; 
     74                                } else if (fb_.match2.pos[1] eq 1 and fb_.match2.len[1] eq fb_.nameLen) { 
     75                                        fb_.name = fb_.verbInfo.attributes.name; 
     76                                } else { 
     77                                        fb_throw("fusebox.badGrammar.invalidAttributeValue", 
     78                                                                "Attribute has invalid value", 
     79                                                                "The attribute 'name' must be a simple variable name, optionally qualified by a scope name, for a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     80                                } 
     81                                // value - string - optional 
     82                                // strict mode - check attribute count: 
     83                                if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) { 
     84                                        if (structCount(fb_.verbInfo.attributes) neq 2) { 
     85                                                fb_throw("fusebox.badGrammar.unexpectedAttributes", 
     86                                                                        "Unexpected attributes", 
     87                                                                        "Unexpected attributes were found in a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     88                                        } 
     89                                } 
     90                                 
     91                                // append this parameter to the parent data: 
     92                                arrayAppend(fb_.verbInfo.parent.parameters,fb_.name); 
     93                                // output the push code: 
     94                                fb_appendLine('<' & 'cfif isDefined("#fb_.name#")><' & 
     95                                                        'cfset myFusebox.stack["#fb_.name#"] = #fb_.name# ></' & 'cfif>'); 
     96                                // reset the value of the "local" variable, if appropriate: 
     97                                if (structKeyExists(fb_.verbInfo.attributes,"value")) { 
     98                                        fb_appendLine('<' & 'cfset #fb_.name# = "#fb_.verbInfo.attributes.value#" />'); 
     99                                } 
     100                                 
     101                        } else if (fb_.verbInfo.parent.lexiconVerb is "xfa") { 
     102 
     103                                // name - string - required 
     104                                if (not structKeyExists(fb_.verbInfo.attributes,"name")) { 
     105                                        fb_throw("fusebox.badGrammar.requiredAttributeMissing", 
     106                                                                "Required attribute is missing", 
     107                                                                "The attribute 'name' is required, for a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     108                                } 
     109                                // value - string - required 
     110                                if (not structKeyExists(fb_.verbInfo.attributes,"value")) { 
     111                                        fb_throw("fusebox.badGrammar.requiredAttributeMissing", 
     112                                                                "Required attribute is missing", 
     113                                                                "The attribute 'value' is required, for a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     114                                } 
     115                                fb_.parameter = structNew(); 
     116                                fb_.parameter.name = fb_.verbInfo.attributes.name; 
     117                                fb_.parameter.value = fb_.verbInfo.attributes.value; 
     118                                // append this parameter to the parent data: 
     119                                arrayAppend(fb_.verbInfo.parent.parameters,fb_.parameter); 
     120 
     121                        } else { 
     122 
     123                                fb_throw("fusebox.badGrammar.parameterInvalidParent", 
     124                                                        "Verb 'parameter' has invalid parent verb", 
     125                                                        "Found 'parameter' verb with no valid parent verb (either 'include' or 'xfa') in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     126 
     127                        } 
     128 
     129                } else { 
     130 
     131                        fb_throw("fusebox.badGrammar.parameterInvalidParent", 
     132                                                "Verb 'parameter' has invalid parent verb", 
     133                                                "Found 'parameter' verb with no valid parent verb (either 'include' or 'xfa') in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     134 
    59135                } 
    60                 fb_.match1 = REFind("[A-Za-z0-9_]*",fb_.verbInfo.attributes.name,1,true); 
    61                 fb_.match2 = REFind("[A-Za-z0-9_]*\.[A-Za-z0-9_]*",fb_.verbInfo.attributes.name,1,true); 
    62                 fb_.nameLen = len(fb_.verbInfo.attributes.name); 
    63                 if (fb_.match1.pos[1] eq 1 and fb_.match1.len[1] eq fb_.nameLen) { 
    64                         fb_.name = "variables." & fb_.verbInfo.attributes.name; 
    65                 } else if (fb_.match2.pos[1] eq 1 and fb_.match2.len[1] eq fb_.nameLen) { 
    66                         fb_.name = fb_.verbInfo.attributes.name; 
    67                 } else { 
    68                         fb_throw("fusebox.badGrammar.invalidAttributeValue", 
    69                                                 "Attribute has invalid value", 
    70                                                 "The attribute 'name' must be a simple variable name, optionally qualified by a scope name, for a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
    71                 } 
    72                 // value - string - optional 
    73                 // must be nested inside an <include> 
    74                 if (not structKeyExists(fb_.verbInfo,"parent") or fb_.verbInfo.parent.lexiconVerb is not "include") { 
    75                         fb_throw("fusebox.badGrammar.parameterNeedsInclude", 
    76                                                 "Verb 'parameter' has no parent 'include' verb", 
    77                                                 "Found 'parameter' verb with no valid parent 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
    78                 } 
    79                 // strict mode - check attribute count: 
    80                 if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) { 
    81                         if (structCount(fb_.verbInfo.attributes) neq 2) { 
    82                                 fb_throw("fusebox.badGrammar.unexpectedAttributes", 
    83                                                         "Unexpected attributes", 
    84                                                         "Unexpected attributes were found in a 'parameter' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
    85                         } 
    86                 } 
    87                  
    88                 // append this argument to the parent data: 
    89                 arrayAppend(fb_.verbInfo.parent.parameters,fb_.name); 
    90                 // output the push code: 
    91                 fb_appendLine('<' & 'cfif isDefined("#fb_.name#")><' & 
    92                                         'cfset myFusebox.stack["#fb_.name#"] = #fb_.name# ></' & 'cfif>'); 
    93                 // reset the value of the "local" variable, if appropriate: 
    94                 if (structKeyExists(fb_.verbInfo.attributes,"value")) { 
    95                         fb_appendLine('<' & 'cfset #fb_.name# = "#fb_.verbInfo.attributes.value#" />'); 
    96                 } 
     136 
    97137        } 
    98138</cfscript> 
  • framework/trunk/verbs/xfa.cfm

    r267 r290  
    8484                                                "The attribute 'value' is required, for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
    8585                } 
    86                 // strict mode - check attribute count: 
     86                // strict mode - check attribute count and that there are no URL parameters: 
    8787                if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) { 
    8888                        if (structCount(fb_.verbInfo.attributes) neq 4) { 
    8989                                fb_throw("fusebox.badGrammar.unexpectedAttributes", 
    9090                                                        "Unexpected attributes", 
    91                                                         "Unexpected attributes were found in a 'set' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     91                                                        "Unexpected attributes were found in a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     92                        } 
     93                        // do not allow URL parameters in the XFA value: 
     94                        if (find("&",fb_.verbInfo.attributes.value) neq 0) { 
     95                                fb_throw("fusebox.badGrammar.invalidAttributeValue", 
     96                                                        "Attribute has invalid value", 
     97                                                        "The attribute 'value' contains URL parameters, which is not allowed in 'strict' mode, for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
    9298                        } 
    9399                } 
     100                 
     101                // if there are children, set up a parameter block: 
     102                if (fb_.verbInfo.hasChildren) { 
     103                        // do not allow URL parameters in the XFA value: 
     104                        if (find("&",fb_.verbInfo.attributes.value) neq 0) { 
     105                                fb_throw("fusebox.badGrammar.invalidAttributeValue", 
     106                                                        "Attribute has invalid value", 
     107                                                        "The attribute 'value' contains URL parameters, which is not allowed when 'parameter' is present, for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#."); 
     108                        } 
     109                        // this is where the child <parameter> verbs will store the parameter details: 
     110                        fb_.verbInfo.parameters = arrayNew(1); 
     111                } 
     112                 
     113        } else { 
    94114         
    95115                // compile <xfa> 
    96116                name = "xfa." & fb_.verbInfo.attributes.name; 
    97117                value = fb_.verbInfo.attributes.value; 
    98                 // adjust xfa value if it is local to this circuit: 
    99                 // <xfa name="foo" value="bar" /> becomes 
    100                 // <xfa name="foo" value="thiscircuit.bar" /> 
    101                 if (listLen(value,".") lt 2 and not fb_.verbInfo.attributes.evaluate) { 
     118 
     119                if (fb_.verbInfo.attributes.evaluate) { 
     120                        value = "evaluate(" & value & ")"; 
     121                } else if (listLen(value,".") lt 2) { 
     122                        // adjust xfa value if it is local to this circuit: 
     123                        // <xfa name="foo" value="bar" /> becomes 
     124                        // <xfa name="foo" value="thiscircuit.bar" /> 
    102125                        value = fb_.verbInfo.circuit & "." & value; 
     126                } 
     127                // append any parameters to the URL value: 
     128                if (fb_.verbInfo.hasChildren) { 
     129                        fb_.n = arrayLen(fb_.verbInfo.parameters); 
     130                        for (fb_.i = 1; fb_.i lte fb_.n; fb_.i = fb_.i + 1) { 
     131                                value = value & "&" & fb_.verbInfo.parameters[fb_.i].name & 
     132                                                                "=" & fb_.verbInfo.parameters[fb_.i].value; 
     133                        } 
    103134                } 
    104135                value = '"' & value & '"'; 
     
    106137                if (find("##",name) gt 0) { 
    107138                        name = '"' & name & '"'; 
    108                 } 
    109                 if (fb_.verbInfo.attributes.evaluate) { 
    110                         value = "evaluate(" & value & ")"; 
    111139                } 
    112140                if (fb_.verbInfo.attributes.overwrite) {