Skip to content

Commit

Permalink
Backported pallets-eco#266
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Apr 18, 2020
1 parent 29c41b0 commit 75e828e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ Unreleased
- Fixed broken format string in Arabic translation (`#471`_)
- Updated French and Japanese translations. (`#514`_, `#506`_)
- Updated Ukrainian translation (`#433`_)

- ``FieldList`` error list is keeps entries in orders for easier identifcation
of erroring fields (`#257`_, `#407`_)
- :class:`~validators.Length` gives a more helpful error message when
``min`` and ``max`` are the same value (`#266`_)

.. _#257: https://github.com/wtforms/wtforms/issues/257
.. _#266: https://github.com/wtforms/wtforms/pull/266
.. _#407: https://github.com/wtforms/wtforms/pull/407
.. _#475: https://github.com/wtforms/wtforms/pull/475/
.. _#463: https://github.com/wtforms/wtforms/pull/463
.. _#523: https://github.com/wtforms/wtforms/pull/523
Expand Down
2 changes: 2 additions & 0 deletions tests/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_length(self):
self.assertEqual(length(min=6)(self.form, field), None)
self.assertRaises(ValidationError, length(max=5), self.form, field)
self.assertEqual(length(max=6)(self.form, field), None)
self.assertEqual(length(min=6, max=6)(self.form, field), None)

self.assertRaises(AssertionError, length)
self.assertRaises(AssertionError, length, min=5, max=2)
Expand All @@ -111,6 +112,7 @@ def test_length(self):
self.assertTrue('at least 8' in grab(min=8))
self.assertTrue('longer than 5' in grab(max=5))
self.assertTrue('between 2 and 5' in grab(min=2, max=5))
self.assertTrue('exactly 5' in grab(min=5, max=5))

def test_required(self):
self.assertEqual(required()(self.form, DummyField('foobar')), None)
Expand Down
3 changes: 3 additions & 0 deletions wtforms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def __call__(self, form, field):
elif self.min == -1:
message = field.ngettext('Field cannot be longer than %(max)d character.',
'Field cannot be longer than %(max)d characters.', self.max)
elif self.min == self.max:
message = field.ngettext('Field must be exactly %(max)d character long.',
'Field must be exactly %(max)d characters long.', self.max)
else:
message = field.gettext('Field must be between %(min)d and %(max)d characters long.')

Expand Down

0 comments on commit 75e828e

Please sign in to comment.