[Coldbox 3.8.1] Size validation for an optional string property

I have a case where the validation condition is basically {required=false ,size=“0…255”}, meaning “Not every entity must have a value for this string property, but if it does then the length must not exceeed 255 characters” but this will fail because the validate(…) method in the SizeValidator.cfc has its check for simple properties written like this: “if( !isNull(arguments.targetValue) **AND isSimpleValue(**targetValue)){”, meaning it will never cover such a case.

Is this intentional or just something that was not considered necessary in the past?

BTW: Seems the JIRA tracker is currently unreachable or else I would’ve submitted an enhancement request for a use case like this.

What would be the workaround?

In my case, it would be enough to just insert
if( isNull(targetValue) AND min EQ 0 ){
return true;
above the other checks, but I have a weird feeling that I’m overlooking a case where this wouldn’t be the desired behaviour.

In something like hyrule you could write your own validation. Could this not apply here?

It’s pretty easy in ColdBox as well (which is what I’ll have to do as an interim solution), but this is a case that’s generic enough that it’s worth mentioning it in the context of the built-in validators.

I agree, but the string issue you mention will be different for every situation. I think hyrule suffered from this problem as well from memory, there was about 4-5 of hyrule validators that I had to write custom ones for.

Just feels kinda inefficient since it’s actually a rather common use case.

An entity has a string property whose length should not exceed the limit of the database column (hence the size validation to err on the side of caution) and since I want a cleaner database my controllers use the “nullEmptyInclude” argument when they’re populating an entity when a user wants to save an entry…