mirror of https://github.com/apache/nifi.git
NIFI-7055 handle empty split evaluations, which contain only ,
add explict test for " , " updated with counting validator Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #4012
This commit is contained in:
parent
7773681eea
commit
f1c6e92df5
|
@ -575,7 +575,12 @@ public class StandardValidators {
|
|||
if (input == null) {
|
||||
return new ValidationResult.Builder().subject(subject).input(null).explanation("List must have at least one non-empty element").valid(false).build();
|
||||
}
|
||||
|
||||
final String[] list = input.split(",");
|
||||
if (list.length == 0) {
|
||||
return new ValidationResult.Builder().subject(subject).input(null).explanation("List must have at least one non-empty element").valid(false).build();
|
||||
}
|
||||
|
||||
for (String item : list) {
|
||||
String itemToValidate = trimEntries ? item.trim() : item;
|
||||
if (!isEmpty(itemToValidate) || !excludeEmptyEntries) {
|
||||
|
|
|
@ -184,6 +184,25 @@ public class TestStandardValidators {
|
|||
assertFalse(vr.isValid());
|
||||
assertEquals(1, mockValidator.getValidateCallCount());
|
||||
|
||||
// An empty list is the same as null, "" or " "
|
||||
vr = val.validate("List", ",", validationContext);
|
||||
assertFalse(vr.isValid());
|
||||
assertEquals(0, mockValidator.getValidateCallCount());
|
||||
|
||||
vr = val.validate("List", " , ", validationContext);
|
||||
assertFalse(vr.isValid());
|
||||
assertEquals(1, mockValidator.getValidateCallCount());
|
||||
|
||||
// will evaluate to no entry
|
||||
vr = val.validate("List", ",,,,", validationContext);
|
||||
assertFalse(vr.isValid());
|
||||
assertEquals(0, mockValidator.getValidateCallCount());
|
||||
|
||||
// will evaluate to an empty element
|
||||
vr = val.validate("List", ",foo", validationContext);
|
||||
assertFalse(vr.isValid());
|
||||
assertEquals(1, mockValidator.getValidateCallCount());
|
||||
|
||||
vr = val.validate("List", "1", validationContext);
|
||||
assertTrue(vr.isValid());
|
||||
assertEquals(1, mockValidator.getValidateCallCount());
|
||||
|
|
Loading…
Reference in New Issue