Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Breaking Change] Update UDF validator to treat null/empty values as …
…valid (#80)

* Update UDF validator to treat null/empty values as valid

* Bugfix. UDF validator now ignores nulls
  • Loading branch information
homestar9 authored Sep 14, 2023
commit a8cbe0b2d2d2385cb3cc69ff79a5ee1ed8c555a9
5 changes: 0 additions & 5 deletions models/validators/MethodValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ component extends="BaseValidator" accessors="true" singleton {
return true;
}

// return true if no data to check, type needs a data element to be checked.
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
return true;
}

// Validate via method
if (
invoke(
Expand Down
7 changes: 6 additions & 1 deletion models/validators/UDFValidator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ component extends="BaseValidator" accessors="true" singleton {
){
var errorMetadata = {};

// return true if no data to check, type needs a data element to be checked.
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
return true;
}

// Validate against the UDF/closure
var passed = arguments.validationData(
isNull( arguments.targetValue ) ? javacast( "null", "" ) : arguments.targetValue,
arguments.targetValue,
arguments.target,
errorMetadata
);
Expand Down
3 changes: 2 additions & 1 deletion test-harness/tests/specs/ValidationIntegrations.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
params = {
username : "luis",
email : "[email protected]",
password : "luis"
password : "luis",
status : 4 // should not validate
},
method = "post"
);
Expand Down
2 changes: 1 addition & 1 deletion test-harness/tests/specs/validators/UDFValidatorTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
javacast( "null", "" ),
variables.validate3
);
assertEquals( false, r );
assertEquals( true, r );
}

private function validate( value, target ){
Expand Down