mirror of
https://github.com/beetbox/beets.git
synced 2026-02-21 14:56:02 +01:00
Malformed date queries no longer crash
This commit is contained in:
parent
44ff3f782a
commit
2b1353a4f1
3 changed files with 17 additions and 3 deletions
|
|
@ -418,10 +418,14 @@ class Period(object):
|
|||
return None
|
||||
ordinal = string.count('-')
|
||||
if ordinal >= len(cls.date_formats):
|
||||
raise ValueError('date is not in one of the formats '
|
||||
+ ', '.join(cls.date_formats))
|
||||
# Too many components.
|
||||
return None
|
||||
date_format = cls.date_formats[ordinal]
|
||||
date = datetime.strptime(string, date_format)
|
||||
try:
|
||||
date = datetime.strptime(string, date_format)
|
||||
except ValueError:
|
||||
# Parsing failed.
|
||||
return None
|
||||
precision = cls.precisions[ordinal]
|
||||
return cls(date, precision)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ Fixes:
|
|||
the player.
|
||||
* The importer no longer tries to highlight partial differences in numeric
|
||||
quantities (track numbers and durations), which was often confusing.
|
||||
* Date-based queries that are malformed (not parse-able) no longer crash
|
||||
beets and instead fail silently.
|
||||
|
||||
|
||||
1.3.8 (September 17, 2014)
|
||||
|
|
|
|||
|
|
@ -112,6 +112,14 @@ class DateQueryTest(_common.LibTestCase):
|
|||
self.assertEqual(len(matched), 0)
|
||||
|
||||
|
||||
class DateQueryConstructTest(unittest.TestCase):
|
||||
def test_long_numbers(self):
|
||||
DateQuery('added', '1409830085..1412422089')
|
||||
|
||||
def test_too_many_components(self):
|
||||
DateQuery('added', '12-34-56-78')
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue