Skip to content

Commit

Permalink
microformats2.to_as1: don't crash on integer UNIX timestamps in `publ…
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Jan 2, 2025
1 parent 5c29a39 commit 63a4c88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
2 changes: 1 addition & 1 deletion granary/microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions granary/tests/test_microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 63a4c88

Please sign in to comment.