gluon.validators: update IS_STRONG to behave as it did in web2py < 2.15

We used to compare `type(self.upper) == int` but the check was changed
to `isinstance(self.upper, int)`. Because bool is an instance of int but is not
the type int, the meaning of the checks changed to treat False as 0.

This patch specifically differentiates between False and 0.
  - False means "no requirements for this character class".
  - 0 means "exactly 0 of this character class".

Fixes #2093
This commit is contained in:
Seth Kinast
2019-02-13 21:14:05 -08:00
parent ddc99b3552
commit 0077f29d71
2 changed files with 15 additions and 3 deletions
+8
View File
@@ -943,6 +943,14 @@ class TestValidators(unittest.TestCase):
'May not include any lowercase letters',
'May not include any numbers']))
)
rtn = IS_STRONG(special=0, es=True)('Abcde1!')
self.assertEqual(rtn,
('Abcde1!',
'|'.join(['Minimum length is 8',
'May not contain any of the following: ~!@#$%^&*()_+-=?<>,.:;{}[]|']))
)
rtn = IS_STRONG(upper=False, number=False, special=False, es=True)('Abcde1!')
self.assertEqual(rtn, ('Abcde1!', 'Minimum length is 8'))
def test_IS_IMAGE(self):
class DummyImageFile(object):