Sat, 01 Jun 2019 14:17:58 +0300
report invalid ISO dates instead of crashing
header.py | file | annotate | diff | comparison | revisions |
--- a/header.py Sat Jun 01 12:38:35 2019 +0300 +++ b/header.py Sat Jun 01 14:17:58 2019 +0300 @@ -125,8 +125,15 @@ elif self.try_to_match( r'!HISTORY (\d{4}-\d{2}-\d{2}) ([\[{][^\]}]+[\]}]) (.+)$', 'history'): + try: + time_object = datetime.datetime.strptime( + self.groups[0], + '%Y-%m-%d', + ) + except ValueError: + self.parse_error("invalid ISO date in history") result.history.append(HistoryEntry( - date = datetime.datetime.strptime(self.groups[0], '%Y-%m-%d').date(), + date = time_object.date(), user = self.groups[1], text = self.groups[2], ))