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:
Otto Fowler 2020-01-23 09:20:17 -05:00 committed by Matthew Burgess
parent 7773681eea
commit f1c6e92df5
No known key found for this signature in database
GPG Key ID: 05D3DEB8126DAD24
2 changed files with 24 additions and 0 deletions

View File

@ -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) {

View File

@ -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());