Skip to content

Commit a8cbe0b

Browse files
authored
[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
1 parent 8a460ab commit a8cbe0b

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

models/validators/MethodValidator.cfc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ component extends="BaseValidator" accessors="true" singleton {
3838
return true;
3939
}
4040

41-
// return true if no data to check, type needs a data element to be checked.
42-
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
43-
return true;
44-
}
45-
4641
// Validate via method
4742
if (
4843
invoke(

models/validators/UDFValidator.cfc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ component extends="BaseValidator" accessors="true" singleton {
3434
){
3535
var errorMetadata = {};
3636

37+
// return true if no data to check, type needs a data element to be checked.
38+
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
39+
return true;
40+
}
41+
3742
// Validate against the UDF/closure
3843
var passed = arguments.validationData(
39-
isNull( arguments.targetValue ) ? javacast( "null", "" ) : arguments.targetValue,
44+
arguments.targetValue,
4045
arguments.target,
4146
errorMetadata
4247
);

test-harness/tests/specs/ValidationIntegrations.cfc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
159159
params = {
160160
username : "luis",
161161
email : "[email protected]",
162-
password : "luis"
162+
password : "luis",
163+
status : 4 // should not validate
163164
},
164165
method = "post"
165166
);

test-harness/tests/specs/validators/UDFValidatorTest.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
3434
javacast( "null", "" ),
3535
variables.validate3
3636
);
37-
assertEquals( false, r );
37+
assertEquals( true, r );
3838
}
3939

4040
private function validate( value, target ){

0 commit comments

Comments
 (0)