From 17f4e464231c15a4cb87beeda6a64115744cabfa Mon Sep 17 00:00:00 2001 From: niphlod Date: Mon, 23 Feb 2015 21:34:23 +0100 Subject: [PATCH] fixes issue #742 --- gluon/tests/test_validators.py | 4 ++++ gluon/validators.py | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gluon/tests/test_validators.py b/gluon/tests/test_validators.py index ef3ce7cc..21711cc8 100644 --- a/gluon/tests/test_validators.py +++ b/gluon/tests/test_validators.py @@ -280,6 +280,10 @@ class TestValidators(unittest.TestCase): self.assertEqual(rtn, ([1, 2], 'Enter between 10 and 100 values')) rtn = IS_LIST_OF(IS_INT_IN_RANGE(0, 10), maximum=2)([1,2,3]) self.assertEqual(rtn, ([1, 2, 3], 'Enter between 0 and 2 values')) + # regression test for issue 742 + rtn = IS_LIST_OF(minimum=1)('') + self.assertEqual(rtn, ([], 'Enter between 1 and 100 values')) + def test_IS_EMPTY_OR(self): rtn = IS_EMPTY_OR(IS_EMAIL())('abc@def.com') diff --git a/gluon/validators.py b/gluon/validators.py index f8150ecd..ba8c09a9 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -2507,9 +2507,10 @@ class IS_LIST_OF(Validator): ivalue = value if not isinstance(value, list): ivalue = [ivalue] - if not self.minimum is None and len(ivalue) < self.minimum: + ivalue = [i for i in ivalue if str(i).strip()] + if self.minimum is not None and len(ivalue) < self.minimum: return (ivalue, translate(self.error_message) % dict(min=self.minimum, max=self.maximum)) - if not self.maximum is None and len(ivalue) > self.maximum: + if self.maximum is not None and len(ivalue) > self.maximum: return (ivalue, translate(self.error_message) % dict(min=self.minimum, max=self.maximum)) new_value = [] other = self.other @@ -2517,13 +2518,12 @@ class IS_LIST_OF(Validator): if not isinstance(other, (list,tuple)): other = [other] for item in ivalue: - if str(item).strip(): - v = item - for validator in other: - (v, e) = validator(v) - if e: - return (ivalue, e) - new_value.append(v) + v = item + for validator in other: + (v, e) = validator(v) + if e: + return (ivalue, e) + new_value.append(v) ivalue = new_value return (ivalue, None)