Skip to content

Commit

Permalink
TESTBOX-385 #resolve
Browse files Browse the repository at this point in the history
Remove all unsafe references to evaluate
  • Loading branch information
lmajano committed Apr 22, 2024
1 parent 8dc2abc commit 17da095
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
9 changes: 2 additions & 7 deletions system/CollectionExpectation.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ component accessors="true" {
function onMissingMethod( string missingMethodName, any missingMethodArguments ){
if ( isArray( variables.actual ) ) {
for ( var e in variables.actual ) {
// Using evaluate since invoke looses track of positional argument collections
evaluate(
"variables.spec.expect( e ).#arguments.missingMethodName#( argumentCollection=arguments.missingMethodArguments )"
);
invoke( variables.spec.expect( e ), arguments.missingMethodName, arguments.missingMethodArguments );
}
} else if ( isStruct( variables.actual ) ) {
for ( var k in variables.actual ) {
var e = variables.actual[ k ];
evaluate(
"variables.spec.expect( e ).#arguments.missingMethodName#( argumentCollection=arguments.missingMethodArguments )"
);
invoke( variables.spec.expect( e ), arguments.missingMethodName, arguments.missingMethodArguments );
}
} else {
variables.assert.fail( "expectAll() actual is neither array nor struct" );
Expand Down
23 changes: 15 additions & 8 deletions system/MockBox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,26 @@ The Official ColdBox Mocking Factory
/>
<cfargument name="default" required="false" hint="Default value to return if property does not exist"/>
<cfscript>
var thisScope = evaluate( "#arguments.scope#" );
var thisScope = variables;
if( arguments.scope == "this" ){
thisScope = this;
} else if(
!isNull( variables) && variables.keyExists( arguments.scope )
){
thisScope = variables[ arguments.scope ];
}

if ( structKeyExists( thisScope, arguments.name ) ) {
return thisScope[ arguments.name ];
}
if ( structKeyExists( thisScope, arguments.name ) ) {
return thisScope[ arguments.name ];
}

if ( structKeyExists( arguments, "default" ) ) {
return arguments.default;
}
if ( structKeyExists( arguments, "default" ) ) {
return arguments.default;
}
</cfscript>
<cfthrow
type ="MockBox.PropertyDoesNotExist"
message="The property requested #arguments.name# does not exist in the #arguments.scope# scope"
message="The property requested [#arguments.name#] does not exist in the [#arguments.scope#] scope"
>
</cffunction>

Expand Down
2 changes: 1 addition & 1 deletion system/compat/framework/TestCase.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ component extends="testbox.system.BaseSpec" {
* Assert something is defined or not
*/
function assertIsDefined( required o, message = "" ){
this.$assert.isTrue( isDefined( evaluate( "arguments.o" ) ), arguments.message );
this.$assert.isTrue( isDefined( "#arguments.o#" ), arguments.message );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion system/util/MixerUtil.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ component accessors="true" {
* Removes a method in a CFC
*/
function removePropertyMixin( required propertyName, scope = "variables" ){
structDelete( evaluate( arguments.scope ), arguments.propertyName );
if( arguments.scope eq "variables" ){
structDelete( variables, arguments.propertyName );
} else {
structDelete( this, arguments.propertyName );
}
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/specs/mockbox/MockBoxTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
$assert.isEqual( "Majano", mock.$getProperty( name = "luis", scope = "this" ) );
$assert.isEqual( true, mock.$getProperty( name = "cool" ) );
$assert.isEqual( true, mock.$getProperty( name = "cool", scope = "variables" ) );
$assert.isEqual( 7, mock.$getProperty( name = "number", scope = "variables.instance" ) );
$assert.isEqual( 7, mock.$getProperty( name = "number", scope = "instance" ) );
$assert.isEqual( 7, mock.$getProperty( name = "number", scope = "instance" ) );
}

Expand Down

0 comments on commit 17da095

Please sign in to comment.