Skip to content

Commit 6134d40

Browse files
committed
Fix for cases where a non-empty value wasn't passing an empty: false validation check
1 parent 988ccb8 commit 6134d40

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

box.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@
5858
"logs:2018":"server log [email protected] --follow",
5959
"logs:2021":"server log [email protected] --follow"
6060
},
61-
"installPaths":{}
61+
"installPaths":{
62+
"cbi18n":"modules/cbi18n/"
63+
}
6264
}

models/validators/EmptyValidator.cfc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ component extends="BaseValidator" accessors="true" singleton {
4646
}
4747

4848
var isFilled = hasValue( arguments.targetValue );
49-
if ( arguments.validationData && !isFilled ) {
49+
50+
if (
51+
// if it should be empty and it is empty
52+
( arguments.validationData && !isFilled ) ||
53+
// or it shouldn't be empty and is not empty
54+
( !arguments.validationData && isFilled )
55+
) {
5056
return true;
5157
}
5258

59+
5360
// No data, fail it
5461
var args = {
5562
message : "The '#arguments.field#' value should #arguments.validationData ? "" : "not "#be empty",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
8282
it( "fails when given an empty struct", function(){
8383
expect( model.validate( variables.result, this, "test", {}, false ) ).toBeFalse();
8484
} );
85+
86+
it( "does not fail when given a non-empty string", () => {
87+
expect( model.validate( variables.result, this, "test", 10, false ) ).toBeTrue();
88+
} );
8589
} );
8690
} );
8791
}

0 commit comments

Comments
 (0)