Skip to content

Commit f64c7b0

Browse files
committed
Handle null values when filtering constraints
1 parent e378092 commit f64c7b0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

models/ValidationManager.cfc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,16 @@ component accessors="true" serialize="false" singleton {
327327
}
328328

329329
var constraint = arguments.constraints[ key ];
330-
if ( constraint.keyExists( "items" ) || constraint.keyExists( "arrayItem" ) ) {
330+
if (
331+
( constraint.keyExists( "items" ) || constraint.keyExists( "arrayItem" ) ) && !isNull(
332+
arguments.target[ key ]
333+
) && isArray( arguments.target[ key ] )
334+
) {
335+
var items = arguments.target[ key ];
331336
var filteredArray = [];
332337
var arrayConstraints = ( constraint.keyExists( "items" ) ? constraint.items : constraint.arrayItem );
333338
if ( arrayConstraints.keyExists( "constraints" ) || arrayConstraints.keyExists( "nestedConstraints" ) ) {
334-
for ( var item in arguments.target[ key ] ) {
339+
for ( var item in items ) {
335340
if ( isStruct( item ) ) {
336341
arrayAppend(
337342
filteredArray,
@@ -345,18 +350,26 @@ component accessors="true" serialize="false" singleton {
345350
}
346351
}
347352
} else {
348-
filteredArray = arguments.target[ key ];
353+
filteredArray = isNull( arguments.target[ key ] ) ? javacast( "null", "" ) : arguments.target[
354+
key
355+
];
349356
}
350357
filteredTarget[ key ] = filteredArray;
351-
} else if ( constraint.keyExists( "constraints" ) || constraint.keyExists( "nestedConstraints" ) ) {
358+
} else if (
359+
( constraint.keyExists( "constraints" ) || constraint.keyExists( "nestedConstraints" ) ) && !isNull(
360+
arguments.target[ key ]
361+
) && isStruct( arguments.target[ key ] )
362+
) {
352363
filteredTarget[ key ] = filterTargetForConstraints(
353364
target = arguments.target[ key ],
354365
constraints = (
355366
constraint.keyExists( "constraints" ) ? constraint.constraints : constraint.nestedConstraints
356367
)
357368
);
358369
} else {
359-
filteredTarget[ key ] = arguments.target[ key ];
370+
filteredTarget[ key ] = isNull( arguments.target[ key ] ) ? javacast( "null", "" ) : arguments.target[
371+
key
372+
];
360373
}
361374
}
362375
return filteredTarget;

0 commit comments

Comments
 (0)