50139[BUGFIX] StringLengthValidator should not accept empty values
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 1
Review log 1314
-
Bernhard Kraft uploaded patch set 1 10/08/16, 18:06
-
TYPO3com voted on patch set 1 V +1 10/08/16, 18:11 Completed build in 04m 57s on Sat, 8 Oct, 08:11 PM Test Summary: 19512 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-3491
-
Frans Saris commented on patch set 1 CR -1 10/08/16, 18:40
Imo you should use the required validator if you require a string value. Making the min 0 value require a string prevents you from using the stringLenghtValidator without minimum length so if you only want to validate if a string is given it must not be longer then x chars -
Bernhard Kraft commented on patch set 1 10/09/16, 14:54
Currently you can achieve the wanted behaviour by using the "NotEmpty" validator in conjunction with the "StringLength" validator. But I doubt this makes sense. With the patch applied and having a min value of "0" everything is as before and the StringLength validator will still accept an empty value. -
Frank Nägler commented on patch set 1 CR -1 10/14/16, 09:12
As mentioned by Frans, this change is a breaking change, because it change the behavior in case the minimum length is not set. I think this should not be changed and I opt for abandon this patch. -
Bernhard Kraft commented on patch set 1 10/14/16, 19:12
Well then abandon it. But what you wrote is wrong. It is the other way round. -
Frans Saris commented on patch set 1 10/14/16, 19:19
Maybe you could try again to tell us why this change is needed. As far as I see it this would make it impossible to set a validation like: field is empty or when set it has a string eith a length between 5 and 10 -
Bernhard Kraft commented on patch set 1 10/14/16, 19:32
I just found it makes logically no sense to say stringLenght=5-to-10 and then accept empty strings. But of course your use case would not be possible without using a disjunction. So maybe you are right and we should just abandon it and maybe place a note in "StringLenghtValidator" to add an "@validate NotEmpty" when empty strings are not allowed. -
Frans Saris commented on patch set 1 10/15/16, 04:38
Improving (inline)documentation is indeed the way to go here I guess -
Claus Due commented on patch set 1 CR -1 10/18/16, 00:20
I would solve this if necessary with an (early) additional check in the `isValid` method which does `if ($this->isEmpty($value) && $this->options['minimum'] === 0) { return; }` which should have the same effect but preserve current behavior without touching/muting the IMHO intended immutable toggle if the class in general accepts empty values. I'm not sure whether to consider it breaking but it does mean one can validate without needing NotEmpty and the verdict will be different compared to before. But, it would be semantically more correct to return valid in this case. -
Bernhard Kraft commented on patch set 1 10/18/16, 11:06
Maybe an option "allowEmpty" directly in the Validator arguments passed from within the @annotation would be the most sensible solution. It should be set to "allowEmpty=1" by default and be subject to a breaking-change in the next version were "allowEmpty=0" will be the default so to match the semantic meaning of "StringLength" validator. -
Claus Due commented on patch set 1 10/18/16, 11:14
Frankly speaking: adding @NotEmpty is both quicker and easier (annotation argument syntax in mind) to implement - and is already known API. And as you say, even the FEATURE would be a breaking change since it changes the default behavior. Personally I would prefer requiring @NotEmpty. Validators are supposed to work this way, creating a ConjunctionValidator when multiple validators exist and requiring each one to pass. It seems wrong to add such an additional toggle inside a specific validator to make it do what another validator already does. I don't have the same objection about making the ViewHelper correctly interpret the meaning of minimum>0 and receiving an empty value. -
Frans Saris commented on patch set 1 11/27/17, 15:46
Can we abandon this change? -
Benni Mack abandoned the change 03/01/18, 21:01
done as Frans said, no reaction