diff --git a/README.md b/README.md index 1e929fdc..ee39e7fe 100644 --- a/README.md +++ b/README.md @@ -336,6 +336,7 @@ Standardize function and method names in all modules to `to_as1`, `from_as`, etc * `Bluesky.get_activities`: skip unknown record types instead of raising `ValueError`. * `microformats2`: * `object_to_json`: Improve handling of items with multiple types by removing `inReplyTo` from likes, shares, etc ([snarfed/bridgy-fed#941](https://github.com/snarfed/bridgy-fed/issues/941)). + * `to_as1`: don't crash on integer UNIX timestamps in `published` and `updated`. * `rss`: * Support image enclosures, both directions. * `from_as1`: diff --git a/granary/microformats2.py b/granary/microformats2.py index 4eff5c97..7af1a1ee 100644 --- a/granary/microformats2.py +++ b/granary/microformats2.py @@ -171,7 +171,7 @@ def maybe_normalize_iso8601(val): val = get_text(val) try: return dateutil.parser.parse(val).isoformat() - except ValueError as e: + except (OverflowError, ValueError) as e: logger.debug(e) return val diff --git a/granary/tests/test_microformats2.py b/granary/tests/test_microformats2.py index 0a5f5d6d..4ad0b02f 100644 --- a/granary/tests/test_microformats2.py +++ b/granary/tests/test_microformats2.py @@ -1012,6 +1012,18 @@ def test_to_as1_rel_urls_actor_urls_text_title_one_url(self): }, })) + def test_to_as1_bad_timestamps(self): + for bad in ('*', '1735561920000', 'foo'): + self.assert_equals({ + 'objectType': 'note', + 'published': bad, + }, microformats2.to_as1({ + 'type': ['h-entry'], + 'properties': { + 'published': [bad], + }, + })) + def test_hfeed_to_as1(self): self.assert_equals([{ 'objectType': 'activity',