diff --git a/vulnerabilitylookup/helpers.py b/vulnerabilitylookup/helpers.py index 2ad66780..ad3cbfb9 100644 --- a/vulnerabilitylookup/helpers.py +++ b/vulnerabilitylookup/helpers.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import re import sys import configparser @@ -10,9 +11,16 @@ def fromisoformat_wrapper(date_iso: str, /) -> datetime: - # Python < 3.11 cannot load times with a Z instead of +00:00 - if sys.version_info < (3, 11) and date_iso.endswith('Z'): - date_iso = date_iso.replace('Z', '+00:00') + if sys.version_info < (3, 11): + if date_iso.endswith('Z'): + # Python < 3.11 cannot load times with a Z instead of +00:00 + date_iso = date_iso.replace('Z', '+00:00') + + # Sometimes, the string also contains nanoseconds for no good reason, and it fails with python < 3.11 + # Is is useless so we strip that. + frac_sec = re.findall(r'[.](\d+)', date_iso) + if frac_sec and len(frac_sec[0]) > 6: + date_iso = date_iso.replace(frac_sec[0], frac_sec[0][:6]) return datetime.fromisoformat(date_iso)