From a58f25bc3b34400f494f6ad722585fd400719fb6 Mon Sep 17 00:00:00 2001 From: kikuyan Date: Sat, 17 Jul 2021 18:10:46 +0900 Subject: [PATCH] [utils] improve to verify date format --- youtube_dl/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index e722eed58..f75a44e61 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -3081,7 +3081,15 @@ def date_from_str(date_str): unit += 's' delta = datetime.timedelta(**{unit: time}) return today + delta - return datetime.datetime.strptime(date_str, '%Y%m%d').date() + + if re.match(r'^\d{8}$', date_str): + try: + return datetime.datetime.strptime(date_str, '%Y%m%d').date() + except ValueError as err: + errmsg = 'Invalid date: %s (%s)' % (date_str, err) + else: + errmsg = 'Invalid date format: %s (must be 8 digit number)' % date_str + raise ValueError(errmsg) def hyphenate_date(date_str):