From abadbdeed47fe97463248f816057b8c1a6f35d72 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Mon, 2 Dec 2024 17:21:56 +0100 Subject: [PATCH] PICARD-3008: Handle OverflowError in extract_year_from_date --- picard/util/__init__.py | 2 +- test/test_utils.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/picard/util/__init__.py b/picard/util/__init__.py index 59968c7beb..453f647bff 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -946,7 +946,7 @@ def extract_year_from_date(dt): return int(dt.get('year')) else: return parse(dt).year - except (TypeError, ValueError): + except (OverflowError, TypeError, ValueError): return None diff --git a/test/test_utils.py b/test/test_utils.py index d131d9689b..2b5068282c 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -172,6 +172,7 @@ def test_string(self): self.assertEqual(extract_year_from_date('2020-02-28'), 2020) self.assertEqual(extract_year_from_date('2015.02'), 2015) self.assertEqual(extract_year_from_date('2015; 2015'), None) + self.assertEqual(extract_year_from_date('20190303201903032019030320190303'), None) # test for the format as supported by ID3 (https://id3.org/id3v2.4.0-structure): yyyy-MM-ddTHH:mm:ss self.assertEqual(extract_year_from_date('2020-07-21T13:00:00'), 2020)