From d1e5ad515dc56c287f009b386f2735b46041610a Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sun, 27 Jul 2025 01:11:16 +0530 Subject: [PATCH] Fix: gracefully handle blank or malformed PO-Revision-Date in .po headers --- babel/messages/catalog.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py index 9a513fbf8..8dbf94403 100644 --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -97,9 +97,18 @@ def _has_python_brace_format(string: str) -> bool: def _parse_datetime_header(value: str) -> datetime.datetime: - match = re.match(r'^(?P.*?)(?P[+-]\d{4})?$', value) + # Handle blank or missing values + if not value or not value.strip(): + return None - dt = datetime.datetime.strptime(match.group('datetime'), '%Y-%m-%d %H:%M') + match = re.match(r'^(?P.*?)(?P[+-]\d{4})?$', value.strip()) + if not match or not match.group('datetime').strip(): + return None + + try: + dt = datetime.datetime.strptime(match.group('datetime').strip(), '%Y-%m-%d %H:%M') + except ValueError: + return None # Separate the offset into a sign component, hours, and # minutes tzoffset = match.group('tzoffset')