Skip to content

Commit f03da58

Browse files
authored
Merge pull request #39 from coldbox-modules/allow_anything_for_udf
Allow any value for udf
2 parents fa90613 + 69d6bf6 commit f03da58

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

models/validators/UDFValidator.cfc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ component accessors="true" singleton {
3131
any targetValue,
3232
any validationData
3333
){
34-
// return true if no data to check, type needs a data element to be checked.
35-
if ( isNull( arguments.targetValue ) || ( isSimpleValue( arguments.targetValue ) && !len( arguments.targetValue ) ) ) {
36-
return true;
37-
}
34+
// Validate against the UDF/closure
35+
var passed = arguments.validationData(
36+
isNull( arguments.targetValue ) ? javacast( "null", "" ) : arguments.targetValue,
37+
arguments.target
38+
);
3839

39-
// Validate against the UDF/closure
40-
if ( arguments.validationData( arguments.targetValue, arguments.target ) ) {
40+
if ( passed ) {
4141
return true;
4242
}
4343

4444
var args = {
4545
message : "The '#arguments.field#' value does not validate",
4646
field : arguments.field,
4747
validationType : getName(),
48-
rejectedValue : ( isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "" ),
48+
rejectedValue : !isNull( arguments.targetValue ) && isSimpleValue( arguments.targetValue ) ? arguments.targetValue : "",
4949
validationData : arguments.validationData
5050
};
5151

test-harness/Application.cfc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ component{
88

99
// UPDATE THE NAME OF THE MODULE IN TESTING BELOW
1010
request.MODULE_NAME = "cbvalidation";
11-
11+
1212
// Application properties
1313
this.name = hash( getCurrentTemplatePath() );
1414
this.sessionManagement = true;
1515
this.sessionTimeout = createTimeSpan(0,0,15,0);
1616
this.setClientCookies = true;
17-
17+
1818
/**************************************
1919
LUCEE Specific Settings
2020
**************************************/
@@ -58,7 +58,6 @@ component{
5858

5959
// request start
6060
public boolean function onRequestStart(String targetPage){
61-
6261
// Process ColdBox Request
6362
application.cbBootstrap.onRequestStart( arguments.targetPage );
6463

@@ -77,4 +76,4 @@ component{
7776
return application.cbBootstrap.onMissingTemplate( argumentCollection=arguments );
7877
}
7978

80-
}
79+
}

test-harness/box.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
"description":"",
77
"dependencies":{
88
"coldbox":"^5.0.0",
9-
"cbi18n":"^1.4.0"
10-
},
11-
"devDependencies":{
12-
"testbox":"^3.0.0"
9+
"cbi18n":"^1.4.0",
10+
"testbox":"^3.1.0+339"
1311
},
1412
"installPaths":{
1513
"coldbox":"coldbox/",
@@ -19,4 +17,4 @@
1917
"testbox":{
2018
"runner":"http://localhost:60299/tests/runner.cfm"
2119
}
22-
}
20+
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
3232
55,
3333
variables.validate2
3434
);
35-
assertEquals( true, r );
35+
assertEquals( true, r );
36+
37+
// null
38+
r = model.validate(
39+
result,
40+
this,
41+
"test",
42+
javacast( "null", "" ),
43+
variables.validate3
44+
);
45+
assertEquals( false, r );
3646
}
3747

3848
private function validate( value, target ){
@@ -41,6 +51,10 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.mod
4151

4252
private function validate2( value, target ){
4353
return arguments.value gt 4;
44-
}
54+
}
55+
56+
private function validate3( value, target ){
57+
return false;
58+
}
4559

4660
}

0 commit comments

Comments
 (0)