Skip to content

Commit 7f387c4

Browse files
committed
Account for null or missing values
1 parent 8d6674a commit 7f387c4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

models/validators/EmptyValidator.cfc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ component extends="BaseValidator" accessors="true" singleton {
4040
);
4141
}
4242

43+
// return true if no data to check, empty needs a data element to be checked.
44+
if ( isNull( arguments.targetValue ) ) {
45+
return true;
46+
}
47+
4348
var isFilled = hasValue( arguments.targetValue );
4449
if ( arguments.validationData && !isFilled ) {
4550
return true;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
1616
variables.result = createMock( "cbvalidation.models.result.ValidationResult" ).init();
1717
} );
1818

19+
it( "skips over null values", function() {
20+
expect( model.validate( variables.result, this, "test", javacast( "null", "" ), true ) ).toBeTrue();
21+
} );
22+
1923
describe( "empty: true", function(){
2024
it( "passes when given an empty string", function(){
2125
expect( model.validate( variables.result, this, "test", "", true ) ).toBeTrue();

0 commit comments

Comments
 (0)