Skip to content

Commit

Permalink
Backported pallets-eco#548
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Apr 20, 2020
1 parent 876fdfb commit b56f1b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Unreleased
if the given validators are both callable, and not classes (`#298`_, `#410`_)
- form.errors is not cached and will update if an error is appended to a field
after access. (`#568`_)
- :class:`~wtforms.validators.NumberRange` correctly handle *not a number*
values. (`#505`_, `#548`_)

.. _#238: https://github.com/wtforms/wtforms/issues/238
.. _#239: https://github.com/wtforms/wtforms/issues/239
Expand All @@ -50,8 +52,10 @@ Unreleased
.. _#410: https://github.com/wtforms/wtforms/pull/410
.. _#475: https://github.com/wtforms/wtforms/pull/475
.. _#463: https://github.com/wtforms/wtforms/pull/463
.. _#505: https://github.com/wtforms/wtforms/pull/505
.. _#523: https://github.com/wtforms/wtforms/pull/523
.. _#524: https://github.com/wtforms/wtforms/pull/524
.. _#548: https://github.com/wtforms/wtforms/pull/548
.. _#483: https://github.com/wtforms/wtforms/pull/483
.. _#485: https://github.com/wtforms/wtforms/pull/485
.. _#471: https://github.com/wtforms/wtforms/pull/471
Expand Down
6 changes: 6 additions & 0 deletions tests/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from functools import partial
from tests.common import DummyField, grab_error_message, grab_stop_message
import decimal


class DummyForm(dict):
Expand Down Expand Up @@ -226,6 +227,11 @@ def test_number_range(self):
self.assertEqual(onlymax(self.form, DummyField(30)), None)
self.assertRaises(ValidationError, onlymax, self.form, DummyField(75))

def test_number_range_nan(self):
validator = NumberRange(0, 10)
for nan in (float("Nan"), decimal.Decimal("NaN")):
self.assertRaises(ValidationError, validator, self.form, DummyField(nan))

def test_lazy_proxy(self):
"""Tests that the validators support lazy translation strings for messages."""

Expand Down
3 changes: 2 additions & 1 deletion wtforms/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

import math
import re
import uuid
import warnings
Expand Down Expand Up @@ -134,7 +135,7 @@ def __init__(self, min=None, max=None, message=None):

def __call__(self, form, field):
data = field.data
if data is None or (self.min is not None and data < self.min) or \
if data is None or math.isnan(data) or (self.min is not None and data < self.min) or \
(self.max is not None and data > self.max):
message = self.message
if message is None:
Expand Down

0 comments on commit b56f1b4

Please sign in to comment.