mirror of
https://github.com/django/django.git
synced 2025-04-02 20:46:41 +00:00
Fixed #34424 -- Fixed SelectDateWidget crash for inputs raising OverflowError.
This commit is contained in:
parent
b4870e7196
commit
d22209cb42
@ -1161,6 +1161,8 @@ class SelectDateWidget(Widget):
|
||||
# Return pseudo-ISO dates with zeros for any unselected values,
|
||||
# e.g. '2017-0-23'.
|
||||
return "%s-%s-%s" % (y or 0, m or 0, d or 0)
|
||||
except OverflowError:
|
||||
return "0-0-0"
|
||||
return date_value.strftime(input_format)
|
||||
return data.get(name)
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from datetime import date, datetime
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
@ -36,6 +37,17 @@ class DateFieldTest(SimpleTestCase):
|
||||
d = GetDate({"mydate_month": "1", "mydate_day": "1", "mydate_year": "2010"})
|
||||
self.assertIn('<label for="id_mydate_month">', d.as_p())
|
||||
|
||||
# Inputs raising an OverflowError.
|
||||
e = GetDate(
|
||||
{
|
||||
"mydate_month": str(sys.maxsize + 1),
|
||||
"mydate_day": "31",
|
||||
"mydate_year": "2010",
|
||||
}
|
||||
)
|
||||
self.assertIs(e.is_valid(), False)
|
||||
self.assertEqual(e.errors, {"mydate": ["Enter a valid date."]})
|
||||
|
||||
@translation.override("nl")
|
||||
def test_l10n_date_changed(self):
|
||||
"""
|
||||
|
@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from datetime import date
|
||||
|
||||
from django.forms import DateField, Form, SelectDateWidget
|
||||
@ -610,6 +611,7 @@ class SelectDateWidgetTest(WidgetTest):
|
||||
((None, "12", "1"), None),
|
||||
(("2000", None, "1"), None),
|
||||
(("2000", "12", None), None),
|
||||
((str(sys.maxsize + 1), "12", "1"), "0-0-0"),
|
||||
]
|
||||
for values, expected in tests:
|
||||
with self.subTest(values=values):
|
||||
|
Loading…
x
Reference in New Issue
Block a user